fix: setContainer in onBeforeMount for drawer (#6986)

* fix: setContainer in onBeforeMount for drawer

* fix: add judgement
pull/7025/head
Konv Suu 2023-10-16 02:56:28 -05:00 committed by GitHub
parent 4428423be4
commit 449adb03df
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 15 additions and 6 deletions

View File

@ -23,14 +23,24 @@ export default defineComponent({
// getContainer // getContainer
let container: HTMLElement; let container: HTMLElement;
const { shouldRender } = useInjectPortal(); const { shouldRender } = useInjectPortal();
onBeforeMount(() => {
isSSR = false; function setContainer() {
});
onMounted(() => {
if (shouldRender.value) { if (shouldRender.value) {
container = props.getContainer(); 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, () => { const stopWatch = watch(shouldRender, () => {
if (shouldRender.value && !container) { if (shouldRender.value && !container) {
container = props.getContainer(); container = props.getContainer();

View File

@ -90,8 +90,7 @@ const Holder = defineComponent({
closable: false, closable: false,
closeIcon: mergedCloseIcon, closeIcon: mergedCloseIcon,
duration: props.duration ?? DEFAULT_DURATION, duration: props.duration ?? DEFAULT_DURATION,
getContainer: () => getContainer: props.staticGetContainer ?? getPopupContainer.value,
props.staticGetContainer?.() || getPopupContainer.value?.() || document.body,
maxCount: props.maxCount, maxCount: props.maxCount,
onAllRemoved: props.onAllRemoved, onAllRemoved: props.onAllRemoved,
}); });