shenrongliang
2025-05-26 e47692e7a147f98c298429a2eaa6a4085d6f795d
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
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)
}