提交 | 用户 | 时间 | ||
314507 | 1 | import { Slots } from 'vue' |
H | 2 | import { isFunction } from '@/utils/is' |
3 | ||
4 | export const getSlot = (slots: Slots, slot = 'default', data?: Recordable) => { | |
5 | // Reflect.has 判断一个对象是否存在某个属性 | |
6 | if (!slots || !Reflect.has(slots, slot)) { | |
7 | return null | |
8 | } | |
9 | if (!isFunction(slots[slot])) { | |
10 | console.error(`${slot} is not a function!`) | |
11 | return null | |
12 | } | |
13 | const slotFn = slots[slot] | |
14 | if (!slotFn) return null | |
15 | return slotFn(data) | |
16 | } |