vue中使用动态组件

在模板文件中引入

<component :is="handleComponent" />

在js中使用

const handleView = (viewUrl) => import('../' + viewUrl) //引入文件路径
export default {
    data(){
        return {
            handleComponent: null,        
        }    
    },
    methods:{
        getRouter(){
           handleView('文件地址').then((component) => {
              this.handleComponent = component.default
           })         
        }    
    }
}

方法和传参与父子组件一致

posted @ 2023-03-06 15:29  大BUG  阅读(22)  评论(0编辑  收藏  举报