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; }; },