diff --git a/src/mixins/popup/index.js b/src/mixins/popup/index.js index aa0a7369c..cb9529cf0 100644 --- a/src/mixins/popup/index.js +++ b/src/mixins/popup/index.js @@ -1,10 +1,16 @@ +// Context import { context } from './context'; +import { openOverlay, closeOverlay, updateOverlay } from './overlay'; + +// Utils +import { on, off, preventDefault } from '../../utils/dom/event'; +import { removeNode } from '../../utils/dom/node'; +import { getScroller } from '../../utils/dom/scroll'; + +// Mixins import { TouchMixin } from '../touch'; import { PortalMixin } from '../portal'; import { CloseOnPopstateMixin } from '../close-on-popstate'; -import { on, off, preventDefault } from '../../utils/dom/event'; -import { openOverlay, closeOverlay, updateOverlay } from './overlay'; -import { getScroller } from '../../utils/dom/scroll'; export const popupMixinProps = { // whether to show popup @@ -90,8 +96,8 @@ export function PopupMixin(options = {}) { beforeDestroy() { this.close(); - if (this.getContainer && this.$parent && this.$parent.$el) { - this.$parent.$el.appendChild(this.$el); + if (this.getContainer) { + removeNode(this.$el); } }, diff --git a/src/toast/index.js b/src/toast/index.js index 87ff23f38..25d5bb0a0 100644 --- a/src/toast/index.js +++ b/src/toast/index.js @@ -1,6 +1,7 @@ import Vue from 'vue'; import VueToast from './Toast'; import { isObject, isServer } from '../utils'; +import { removeNode } from '../utils/dom/node'; const defaultOptions = { icon: '', @@ -100,11 +101,7 @@ function Toast(options = {}) { clearTimeout(toast.timer); queue = queue.filter(item => item !== toast); - const parent = toast.$el.parentNode; - if (parent) { - parent.removeChild(toast.$el); - } - + removeNode(toast.$el); toast.$destroy(); }); } diff --git a/src/utils/dom/node.ts b/src/utils/dom/node.ts new file mode 100644 index 000000000..07756867a --- /dev/null +++ b/src/utils/dom/node.ts @@ -0,0 +1,7 @@ +export function removeNode(el: Node) { + const parent = el.parentNode; + + if (parent) { + parent.removeChild(el); + } +}