场景:
存在A、B、C三个组件,A有调用B,B有调用C,C会调用自身,同一个子组件被多次调用,就导致控制台抛错
[Vue warn]: Unknown custom element: - did you register
the component correctly? For recursive components, make sure to
provide the “name” option.
解决方案:
注册全局组件:
1、在components文件夹下创建layoutModule组件
<template>
<div>
{{msg}}
</div>
</template>
<script>
export default {
data() {
return {
msg:'组件内容'
}
}
}
</script>
2、在main.js文件中引入自定义组件并注册
import layoutModule from '@/components/layoutModule/'
Vue.component('layoutModule', layoutModule)
new Vue({
el: '#app'
render: h => h(App)
})
3、引入使用
<layout-module></layout-module>