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.
22 lines
395 B
22 lines
395 B
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'}); |
|
} |
|
}); |
|
}
|
|
|