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