App挂载

作者: 二荣xxx | 来源:发表于2021-03-02 12:46 被阅读0次

    一、createApp挂载

    import Dialog from './Dialog.vue';
    import {createApp} from 'vue';
    
    export const openDialog = () => {
      const div = document.createElement('div');
      document.body.appendChild(div);
      createApp(Dialog).mount(div);  //将Dialog挂载到div上
    }
    

    createApp接受第二个参数h

    import Dialog from './Dialog.vue';
    import {createApp, h} from 'vue';
    
    export const openDialog = (options) => {
      const {title, content, ok, cancel,closeOnclickOverlay} = options;
      const div = document.createElement('div');
      document.body.appendChild(div);
      const app = createApp({
        render() {
          return h(Dialog, { //渲染Dialog并传参
            visible: true, 'onUpdate:visible': (newVisible) => {
              if (newVisible === false) {
                app.unmount(div); 
                div.remove();
              }
            },
          }, {title, content}); //插槽的参数
        }
      });
      app.mount(div);
    };
    
    

    相关文章

      网友评论

          本文标题:App挂载

          本文链接:https://www.haomeiwen.com/subject/ytfzfltx.html