github.com/e154/smart-home@v0.17.2-0.20240311175135-e530a6e5cd45/static_source/admin/src/utils/tsxHelper.ts (about)

     1  import { Slots } from 'vue'
     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  }