feat(@vant/use): add onMountedOrActivated

This commit is contained in:
chenjiahan 2020-11-11 20:43:24 +08:00
parent ed332daf31
commit 6db84d7c2b
2 changed files with 21 additions and 2 deletions

View File

@ -1,10 +1,11 @@
export * from './utils';
export * from './useRect'; export * from './useRect';
export * from './useToggle'; export * from './useToggle';
export * from './useRelation';
export * from './useCountDown'; export * from './useCountDown';
export * from './useClickAway'; export * from './useClickAway';
export * from './useWindowSize'; export * from './useWindowSize';
export * from './useScrollParent'; export * from './useScrollParent';
export * from './useEventListener'; export * from './useEventListener';
export * from './usePageVisibility'; export * from './usePageVisibility';
export * from './useRelation'; export * from './onMountedOrActivated';
export * from './utils';

View File

@ -0,0 +1,18 @@
import { nextTick, onMounted, onActivated } from 'vue';
export function onMountedOrActivated(hook: () => any) {
let mounted: boolean;
onMounted(() => {
hook();
nextTick(() => {
mounted = true;
});
});
onActivated(() => {
if (mounted) {
hook();
}
});
}