From 449adb03df6829476929f8d56e4e2b0e21a5cc23 Mon Sep 17 00:00:00 2001 From: Konv Suu <2583695112@qq.com> Date: Mon, 16 Oct 2023 02:56:28 -0500 Subject: [PATCH] fix: setContainer in onBeforeMount for drawer (#6986) * fix: setContainer in onBeforeMount for drawer * fix: add judgement --- components/_util/Portal.tsx | 18 ++++++++++++++---- components/message/useMessage.tsx | 3 +-- 2 files changed, 15 insertions(+), 6 deletions(-) diff --git a/components/_util/Portal.tsx b/components/_util/Portal.tsx index 7b4f682b2..caba27b22 100644 --- a/components/_util/Portal.tsx +++ b/components/_util/Portal.tsx @@ -23,14 +23,24 @@ export default defineComponent({ // getContainer 不会改变,不用响应式 let container: HTMLElement; const { shouldRender } = useInjectPortal(); - onBeforeMount(() => { - isSSR = false; - }); - onMounted(() => { + + function setContainer() { if (shouldRender.value) { container = props.getContainer(); } + } + + onBeforeMount(() => { + isSSR = false; + // drawer + setContainer(); }); + onMounted(() => { + if (container) return; + // https://github.com/vueComponent/ant-design-vue/issues/6937 + setContainer(); + }); + const stopWatch = watch(shouldRender, () => { if (shouldRender.value && !container) { container = props.getContainer(); diff --git a/components/message/useMessage.tsx b/components/message/useMessage.tsx index c2fc8992f..e4e929eb2 100644 --- a/components/message/useMessage.tsx +++ b/components/message/useMessage.tsx @@ -90,8 +90,7 @@ const Holder = defineComponent({ closable: false, closeIcon: mergedCloseIcon, duration: props.duration ?? DEFAULT_DURATION, - getContainer: () => - props.staticGetContainer?.() || getPopupContainer.value?.() || document.body, + getContainer: props.staticGetContainer ?? getPopupContainer.value, maxCount: props.maxCount, onAllRemoved: props.onAllRemoved, });