mirror of
https://gitee.com/vant-contrib/vant.git
synced 2025-04-06 03:57:59 +08:00
fix(Popup): may throw error when using get-container and destroyed
This commit is contained in:
parent
14ddf449a5
commit
52aa9e8559
@ -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);
|
||||
}
|
||||
},
|
||||
|
||||
|
@ -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();
|
||||
});
|
||||
}
|
||||
|
7
src/utils/dom/node.ts
Normal file
7
src/utils/dom/node.ts
Normal file
@ -0,0 +1,7 @@
|
||||
export function removeNode(el: Node) {
|
||||
const parent = el.parentNode;
|
||||
|
||||
if (parent) {
|
||||
parent.removeChild(el);
|
||||
}
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user