mirror of
https://github.com/vbenjs/vue-vben-admin.git
synced 2025-08-27 13:21:51 +08:00
feat: 逐步抽离部分包到packages
This commit is contained in:
2
packages/hooks/src/index.ts
Normal file
2
packages/hooks/src/index.ts
Normal file
@@ -0,0 +1,2 @@
|
||||
// life-cycle
|
||||
export * from './lifecycle/onMountedOrActivated';
|
25
packages/hooks/src/lifecycle/onMountedOrActivated.ts
Normal file
25
packages/hooks/src/lifecycle/onMountedOrActivated.ts
Normal 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 };
|
Reference in New Issue
Block a user