<div id="example">
<parent></parent>
</div>
<script type="text/javascript">
// 局部注册
var Child = Vue.extend({
template: '<div>Child</div>'
});
// 为什么 Child 不显示?
var Parent = Vue.extend({
template: `<div>Parent</div>`,
components: {
// child 只能用在父组件模版内
'child': Child
}
});
var vm2 = new Vue({
el: '#example',
components: {
'parent': Parent
}
});
</script>
上面代码,不知道什么原因,为什么 child 组件中 内容不显示?
官方的例子不太理解。
求大神解答?
<div id="example">
<parent></parent>
</div>
<script type="text/javascript">
// 局部注册
var Child = Vue.extend({
template: '<div>Child</div>'
});
// 为什么 Child 不显示?
var Parent = Vue.extend({
template: `<div>Parent:<child></child></div>`,//你的子组件得引到父模版里来
components: {
// child 只能用在父组件模版内
'child': Child
}
});
var vm2 = new Vue({
el: '#example',
components: {
'parent': Parent
}
});
</script>
你得把<child></child>写到parent的template里才行