fix: ssr error
parent
9d469fb2af
commit
b9ff4eabcc
|
@ -1,5 +1,12 @@
|
||||||
import PropTypes from './vue-types';
|
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({
|
export default defineComponent({
|
||||||
name: 'Portal',
|
name: 'Portal',
|
||||||
|
@ -9,9 +16,13 @@ export default defineComponent({
|
||||||
didUpdate: PropTypes.func,
|
didUpdate: PropTypes.func,
|
||||||
},
|
},
|
||||||
setup(props, { slots }) {
|
setup(props, { slots }) {
|
||||||
|
let isSSR = true;
|
||||||
// getContainer 不会改变,不用响应式
|
// getContainer 不会改变,不用响应式
|
||||||
const container = props.getContainer();
|
let container: HTMLElement;
|
||||||
|
onBeforeMount(() => {
|
||||||
|
isSSR = false;
|
||||||
|
container = props.getContainer();
|
||||||
|
});
|
||||||
onUpdated(() => {
|
onUpdated(() => {
|
||||||
nextTick(() => {
|
nextTick(() => {
|
||||||
props.didUpdate?.(props);
|
props.didUpdate?.(props);
|
||||||
|
@ -23,6 +34,9 @@ export default defineComponent({
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
return () => {
|
return () => {
|
||||||
|
if (isSSR) {
|
||||||
|
return slots.default?.();
|
||||||
|
}
|
||||||
return container ? <Teleport to={container} v-slots={slots}></Teleport> : null;
|
return container ? <Teleport to={container} v-slots={slots}></Teleport> : null;
|
||||||
};
|
};
|
||||||
},
|
},
|
||||||
|
|
Loading…
Reference in New Issue