今天在学习vue组件的嵌套时页面报错。
大概的意思是:组件模板应该包含一个根元素。
错误代码:
var childComponent = Vue.extend({
template: '<div>this is child template</div>'
});
Vue.component("parent",{
template: '<div>this is parent template</div><child></child>',
//正确代码
// template: '<p>this is parent template<child></child></p>'
components: {
'child': childComponent,
}
});
var app = new Vue({
el: '#app'
});
原来,我们在使用组件的时候。需要使用div或者p标签等将其包起来