Vue $slots 物件
示例
使用 $slots
物件來檢查父元件是否提供了 'topSlot' 的內容。
mounted(){
if(this.$slots.topSlot){
this.slotsText = "Content for the 'topSlot' slot is provided by the parent."
}
else {
this.slotsText = "Content for the 'topSlot' slot is NOT provided by the parent."
}
}
執行示例 »
定義和用法
$slots
物件表示從父元件傳遞過來的插槽。
可以透過呼叫 this.$slots
來檢視從父元件傳遞過來的插槽,或者呼叫 this.$slots.topSlot
來檢視名為 'topSlot' 的特定插槽。
$slots
物件可以用於檢查父元件是否提供了插槽,就像上面的示例一樣,或者用於編寫渲染函式。
相關頁面
Vue 教程:Vue 插槽
Vue 教程:作用域插槽
Vue 教程:Vue v-slot
Vue 參考:Vue v-slot 指令