Files
jeecgboot-vue3/src/hooks/core/onMountedOrActivated.ts
2023-12-08 12:56:52 +08:00

23 lines
395 B
TypeScript

import { nextTick, onMounted, onActivated } from 'vue';
type HookArgs = {
type: 'mounted' | 'activated';
}
export function onMountedOrActivated(hook: Fn<HookArgs, any>) {
let mounted: boolean;
onMounted(() => {
hook({type: 'mounted'});
nextTick(() => {
mounted = true;
});
});
onActivated(() => {
if (mounted) {
hook({type: 'activated'});
}
});
}