mirror of
https://github.com/element-plus/element-plus.git
synced 2026-03-13 07:51:17 +08:00
chore(utils): improve code style for global-node (#17675)
refactor: improve code style for global-node
This commit is contained in:
@@ -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)
|
||||
}
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user