feat: 逐步抽离部分包到packages

This commit is contained in:
vben
2023-04-05 22:29:16 +08:00
parent a5ed79fc94
commit 279977b817
41 changed files with 726 additions and 60 deletions

View File

@@ -0,0 +1,2 @@
// life-cycle
export * from './lifecycle/onMountedOrActivated';

View File

@@ -0,0 +1,25 @@
import { type AnyFunction } from '@vben/types';
import { nextTick, onMounted, onActivated } from 'vue';
/**
* 在 OnMounted 或者 OnActivated 时触发
* @param hook 任何函数(包括异步函数)
*/
function onMountedOrActivated(hook: AnyFunction) {
let mounted: boolean;
onMounted(() => {
hook();
nextTick(() => {
mounted = true;
});
});
onActivated(() => {
if (mounted) {
hook();
}
});
}
export { onMountedOrActivated };