關於Vue插槽的概念,大家可以從vue官網的api查看,我是看到網站的對於初接觸 這個要概念的人來說不是很清楚,我來貼下原碼,就比較直觀了
貼下原碼:
具名插槽:v-slot:header
Html:
<div id=’app’>
<child>
<template v-slot:header>
<div>this is a header</div>
</template>
</child>
</div>
script部分:
Vue.component(‘child’,{
Template:’<div><slot name=’header’></slot></div>
}
作用域插槽
Html:
<div id=’app’>
<child>
<template v-slot=’list’>
<div>{{list.item}}</div>
</template>
</child>
</div>
script部分:
Vue.component(‘child’,{
data:function(){
return{
List:[1,2,3,4,5,6]
}
}
,
Template:’<div><slot v-for=”item of list” :item=item></slot></div>
}