Files
vue-element-plus-admin/src/utils/tsxHelper.ts
kailong321200875 4612e5544b feat(Breadcrumbe): Add Breadcrumb component
style: change function to arrow function
2022-01-15 14:24:50 +08:00

17 lines
456 B
TypeScript

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)
}