Vue.component('Father',{ template: 'father
'//这里要把子组件加进来 }) Vue.component('Son',{ template: 'son
' }) new Vue({ el: '#app', })
new Vue({ el: '#app', components: { 'Father': { template: 'father',//这里也要把子组件加进来,组件可以使用单标签 components: { 'Son': {//子组件必须在父组件内创建才行 template: 'Son
' } } } } })
Vue.component('Hello',{ template: '#Hello'//这里的作用相当于根实例中的el:'app' ;作用一样,都是挂载 }) new Vue({ el: '#app', })
摘自:
https://blog.csdn.net/zhangyuea/article/details/89421424