$slots
创建于 2024-12-03 /
39
字体:
[默认]
[大]
[更大]
❮ 上一节
下一节 ❯
❮ 上一节 下一节 ❯
示例
使用 $slots
对象检查父级是否已为"topSlot"提供内容。
mounted(){
if(this.$slots.topSlot){
this.slotsText = "'topSlot' 插槽的内容由父级提供。"
}
else {
this.slotsText = "'topSlot' 插槽的内容不是由父级提供的。"
}
}
运行示例 »
定义和用法
$slots
对象表示从父级传递的插槽。
可以通过调用 this.$slots
来查看从父级传递的插槽,或者通过调用 this.$slots.topSlot
来查看名为"topSlot"的特定插槽。
$slots
对象可用于检查父组件是否提供插槽(如上例所示),或用于编写渲染函数。
相关页面
Vue 教程:Vue 插槽
Vue 教程:作用域插槽
Vue 教程:Vue v-slot
Vue 参考:Vue v-slot 指令
❮ 上一节 下一节 ❯
0 人点赞过