methods: {
handleClick (tab, event) {
// 异步加载组件
let getCompoentIndex = this.menu.findIndex(x => x.name === tab.name)
let component = this.menu[getCompoentIndex].component
if (!this.menu[getCompoentIndex].loading) {
this.menu[getCompoentIndex].loading = true
Vue.component(component, function (resolve, reject) {
setTimeout(function () {
require([`./${component}.vue`], resolve)//比如 abc.vue
}, 1000)
})
}
}
}
点击的时候去加载异步组件(可以载入组件),但报下面的错
[Vue warn]: Unknown custom element: - did you register the component correctly? For recursive components, make sure to provide the "name" option.
尝试为abc组件加上name还是报这样的错,有人知道怎么解决吗?
abc.vue
export default {
name: 'abc',
}
Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号
找出了方法就是加上if判断
然后在点击的时候把flag设置为true就解决了那个报错问题
我是用WEBPACK解决的。
可以参看我的项目。