UNPKG

@fe6/water-pro

Version:

An enterprise-class UI design language and Vue-based implementation

25 lines (22 loc) 607 B
import { getCurrentInstance, onUnmounted, Slots } from 'vue'; import { isFunction } from '@fe6/shared'; export function tryOnUnmounted(fn: () => Promise<void> | void) { getCurrentInstance() && onUnmounted(fn); } /** * @description: Get slot to prevent empty error */ export function getSlot(slots: Slots, slot = 'default', data?: any) { 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); }