基本概念:插槽就是子组件中的提供给父组件使用的一个占位符 <slot></slot>
1.插槽的基本使用
<body>
<div id="app">
<base-layout>沉默是金</base-layout>
<base-layout>倩女幽魂</base-layout>
</div>
<script>
Vue.component('base-layout', {
template: `
<div>
<p>歌名</p>
<slot></slot>
</div>`
})
new Vue({
el: '#app',
data() {
return {
}
}
})
</script>
</body>
运行如下图
2. 具名插槽
v-slot写法只能作用于容器中,标签是会报错的,组件位置可以随意摆放