判断某个具名插槽是否存在:
hasSlot(slotName) {
// Vue 3
if (
this.$slots[slotName] &&
typeof this.$slots[slotName] === 'function'
) {
return true
}
// Vue 2
if (this.$scopedSlots && this.$scopedSlots[slotName]) {
return true
}
return false
}
除此之外,也可以借助 vue-demi 这个库,来兼容 vue2 和 vue3 的写法。

4775

被折叠的 条评论
为什么被折叠?



