From 6177bf00a28123068ed8111030165361d7992285 Mon Sep 17 00:00:00 2001 From: Zhousg Date: Sun, 28 May 2023 16:18:54 +0800 Subject: [PATCH] fix(Popup): opened event is emitted twice when duration is 0 (#11902) * fix(Popup): duration 0s and enable lazyRender opened is executed twice * fix(Popup): optimized code --- packages/vant/src/popup/Popup.tsx | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/packages/vant/src/popup/Popup.tsx b/packages/vant/src/popup/Popup.tsx index 2c37674ad..f5fecfa6e 100644 --- a/packages/vant/src/popup/Popup.tsx +++ b/packages/vant/src/popup/Popup.tsx @@ -172,7 +172,14 @@ export default defineComponent({ } }; - const onOpened = () => emit('opened'); + // see: https://github.com/youzan/vant/issues/11901 + let timer: ReturnType | null; + const onOpened = () => { + if (timer) clearTimeout(timer); + timer = setTimeout(() => { + emit('opened'); + }); + }; const onClosed = () => emit('closed'); const onKeydown = (event: KeyboardEvent) => emit('keydown', event);