@fe6/water-pro
Version:
An enterprise-class UI design language and Vue-based implementation
30 lines (24 loc) • 700 B
JavaScript
import { getCurrentInstance, onUnmounted } from 'vue';
import { isFunction } from '@fe6/shared';
export function tryOnUnmounted(fn) {
getCurrentInstance() && onUnmounted(fn);
}
/**
* @description: Get slot to prevent empty error
*/
export function getSlot(slots) {
var slot = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 'default';
var data = arguments.length > 2 ? arguments[2] : undefined;
if (!slots || !Reflect.has(slots, slot)) {
return null;
}
if (!isFunction(slots[slot])) {
console.error("".concat(slot, " is not a function!"));
return null;
}
var slotFn = slots[slot];
if (!slotFn) {
return null;
}
return slotFn(data);
}