You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
23 lines
395 B
23 lines
395 B
2 months ago
|
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'});
|
||
|
}
|
||
|
});
|
||
|
}
|