组件之间的嵌套要将子组件以标签化的形式放在父组件的模板中使用
组件全局
<body>
<div id="app">
<Father></Father>
<!--
直接这么写是不行的
<Father>
<Son></Son>
</Father>
-->
</div>
<template id="father">
<div>
<h3> father </h3>
<hr>
<Son/>
</div>
</template>
<template id="son">
<h5> son </h5>
</template>
</body>
<script src="../../../lib/vue.js"></script>
<script>
Vue.component('Father',{
template: '#father'
})
Vue.component('Son',{
template: '#son'
})
new Vue({
el: '#app'
})
</script>
组件局部
<body>
<div id="app">
<Father></Father>
</div>
<template id="father">
<div>
<h3> father </h3>
<hr>
<Son/>
</div>
</template>
<template id="son">
<h5> son </h5>
</template>
</body>
<script src="../../../lib/vue.js"></script>
<script>
new Vue({
el: '#app',
components: {
'Father': {
template: '#father',
components: {
'Son': {
template: '#son'
}
}
}
}
})
</script>