From b9ff4eabccb600af46d4b9829d4793876734b701 Mon Sep 17 00:00:00 2001 From: tangjinzhou <415800467@qq.com> Date: Sun, 12 Dec 2021 16:47:30 +0800 Subject: [PATCH] fix: ssr error --- components/_util/Portal.tsx | 20 +++++++++++++++++--- 1 file changed, 17 insertions(+), 3 deletions(-) diff --git a/components/_util/Portal.tsx b/components/_util/Portal.tsx index c856175b9..c35ab9b32 100644 --- a/components/_util/Portal.tsx +++ b/components/_util/Portal.tsx @@ -1,5 +1,12 @@ import PropTypes from './vue-types'; -import { defineComponent, nextTick, onBeforeUnmount, onUpdated, Teleport } from 'vue'; +import { + defineComponent, + nextTick, + onBeforeMount, + onBeforeUnmount, + onUpdated, + Teleport, +} from 'vue'; export default defineComponent({ name: 'Portal', @@ -9,9 +16,13 @@ export default defineComponent({ didUpdate: PropTypes.func, }, setup(props, { slots }) { + let isSSR = true; // getContainer 不会改变,不用响应式 - const container = props.getContainer(); - + let container: HTMLElement; + onBeforeMount(() => { + isSSR = false; + container = props.getContainer(); + }); onUpdated(() => { nextTick(() => { props.didUpdate?.(props); @@ -23,6 +34,9 @@ export default defineComponent({ } }); return () => { + if (isSSR) { + return slots.default?.(); + } return container ? : null; }; },