diff --git a/packages/utils/vue/global-node.ts b/packages/utils/vue/global-node.ts index 5eec277c97..8244f48cfc 100644 --- a/packages/utils/vue/global-node.ts +++ b/packages/utils/vue/global-node.ts @@ -1,7 +1,7 @@ import { isClient } from '../browser' const globalNodes: HTMLElement[] = [] -let target: HTMLElement = !isClient ? (undefined as any) : document.body +let target: HTMLElement | undefined = !isClient ? undefined : document.body export function createGlobalNode(id?: string) { const el = document.createElement('div') @@ -9,8 +9,10 @@ export function createGlobalNode(id?: string) { el.setAttribute('id', id) } - target.appendChild(el) - globalNodes.push(el) + if (target) { + target.appendChild(el) + globalNodes.push(el) + } return el } @@ -25,7 +27,7 @@ export function changeGlobalNodesTarget(el: HTMLElement) { target = el globalNodes.forEach((el) => { - if (el.contains(target) === false) { + if (target && !el.contains(target)) { target.appendChild(el) } })