tsxHelper.ts 456 B

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