mirror of
https://github.com/youzan/vant.git
synced 2025-10-17 16:44:21 +00:00
feat(@vant/use): add onMountedOrActivated
This commit is contained in:
@@ -1,10 +1,11 @@
|
||||
export * from './utils';
|
||||
export * from './useRect';
|
||||
export * from './useToggle';
|
||||
export * from './useRelation';
|
||||
export * from './useCountDown';
|
||||
export * from './useClickAway';
|
||||
export * from './useWindowSize';
|
||||
export * from './useScrollParent';
|
||||
export * from './useEventListener';
|
||||
export * from './usePageVisibility';
|
||||
export * from './useRelation';
|
||||
export * from './utils';
|
||||
export * from './onMountedOrActivated';
|
||||
|
18
packages/vant-use/src/onMountedOrActivated/index.ts
Normal file
18
packages/vant-use/src/onMountedOrActivated/index.ts
Normal 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();
|
||||
}
|
||||
});
|
||||
}
|
Reference in New Issue
Block a user