插槽
把所有代码比作一条路,插槽就是在路上砸个坑将制定内容放进去
<body>
<div id="app">
<child-one>
<a href="#">外面传入的</a>
<a href="#">外面传入的</a>
</child-one>
</div>
<script>
Vue.component("child-one",{
props:{
},
template:`<div>
<slot>你没有传入内容</slot>
</div>`
})
let vue=new Vue({
el:"#app",
components:{
},
data:{
},
})
</script>
</body>
</html>
具名插槽,就是给这个插槽起个名字
在组件中,我给插槽起个名字,一个名字叫"bd",一个名字叫"xl",还有一个不起名字。
然后再内,slot属性对应的内容都会和组件中name一一对应。
而没有名字的,就是默认插槽!!
<body>
<div id="app">
<child-one>
<a href="#" slot="bd">百度</a>
<a href="#" slot="xl">新浪</a>
<a href="#" ">无名小站</a>
</child-one>
</div>
<script>
Vue.component("child-one",{
props:{
},
template:`<div>
<slot name="bd">你没有给插槽传入内容</slot>
<hr>
<slot name="xl">你没有给插槽传入内容</slot>
<hr>
<slot>你没有给插槽传入内容</slot>
</div>`
})
let vue=new Vue({
el:"#app",
components:{
},
data:{
},
})
</script>
</body>
</html>