feat: add onPopupReopen (#8641)

This commit is contained in:
neverland 2021-05-01 16:40:50 +08:00 committed by GitHub
parent 161b5980eb
commit b43822562f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 23 additions and 0 deletions

View File

@ -0,0 +1,19 @@
import { inject, watch } from 'vue';
// eslint-disable-next-line
export const POPUP_TOGGLE_KEY = Symbol();
export function onPopupReopen(callback: () => void) {
const popupToggleStatus = inject<(() => boolean) | null>(
POPUP_TOGGLE_KEY,
null
);
if (popupToggleStatus) {
watch(popupToggleStatus, (show) => {
if (show) {
callback();
}
});
}
}

View File

@ -1,6 +1,7 @@
import {
ref,
watch,
provide,
Teleport,
computed,
PropType,
@ -21,6 +22,7 @@ import { useEventListener } from '@vant/use';
import { useExpose } from '../composables/use-expose';
import { useLockScroll } from '../composables/use-lock-scroll';
import { useLazyRender } from '../composables/use-lazy-render';
import { POPUP_TOGGLE_KEY } from '../composables/on-popup-reopen';
// Components
import { Icon } from '../icon';
@ -245,6 +247,8 @@ export default defineComponent({
}
});
provide(POPUP_TOGGLE_KEY, () => props.show);
return () => {
if (props.teleport) {
return (