You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
17 lines
456 B
17 lines
456 B
8 months ago
|
import { Slots } from 'vue'
|
||
|
import { isFunction } from '@/utils/is'
|
||
|
|
||
|
export const getSlot = (slots: Slots, slot = 'default', data?: Recordable) => {
|
||
|
// Reflect.has 判断一个对象是否存在某个属性
|
||
|
if (!slots || !Reflect.has(slots, slot)) {
|
||
|
return null
|
||
|
}
|
||
|
if (!isFunction(slots[slot])) {
|
||
|
console.error(`${slot} is not a function!`)
|
||
|
return null
|
||
|
}
|
||
|
const slotFn = slots[slot]
|
||
|
if (!slotFn) return null
|
||
|
return slotFn(data)
|
||
|
}
|