Vue.js 创建父、子组件

??
在父组件中注册子组件后,在父组件模板template中使用子组件时,应该把父组件模板内容和子组件标签放在同一个HTML标签内,否则会报错无法显示:
父组件内容 <子组件>

Vue.js 创建父组件和子组件 - 锐客网 src="https://www.it610.com/article/vue.js" type="text/javascript" charset="utf-8">
type="text/javascript"> //Step 1: 创建子组件 var ChildComponent = Vue.extend({ template: 'the child comonent.
' })//Step 2: 创建父组件,并且注册子组件 var ParentComponent = Vue.extend({ template: '【Vue.js 创建父、子组件】the parent component.
', components: { 'child-component': ChildComponent } })//Step 3: 全局注册父组件,子组件也会同时被渲染出来 Vue.component('parent-component', ParentComponent) new Vue({ el: '#app' })

    推荐阅读