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 对象表示从父对象传递的 slot。
可以通过调 this.$slots 此来查看从父级传递的 slot,或通过调用 this.$slots 查看名为 'topSlot' 的特定 slot。
$slots 对象可以用于检查 slot 是否由父组件提供,如上面的实例所示,或者用于编写渲染函数。
关联页面
Vue 教程: Vue Slot
Vue 教程: Vue 范围 Slot
Vue 教程: Vue v-slot
Vue 参考引用: Vue v-slot 指令