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 { 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 { TouchMixin } from '../touch';
|
||||||
import { PortalMixin } from '../portal';
|
import { PortalMixin } from '../portal';
|
||||||
import { CloseOnPopstateMixin } from '../close-on-popstate';
|
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 = {
|
export const popupMixinProps = {
|
||||||
// whether to show popup
|
// whether to show popup
|
||||||
@ -90,8 +96,8 @@ export function PopupMixin(options = {}) {
|
|||||||
beforeDestroy() {
|
beforeDestroy() {
|
||||||
this.close();
|
this.close();
|
||||||
|
|
||||||
if (this.getContainer && this.$parent && this.$parent.$el) {
|
if (this.getContainer) {
|
||||||
this.$parent.$el.appendChild(this.$el);
|
removeNode(this.$el);
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
import Vue from 'vue';
|
import Vue from 'vue';
|
||||||
import VueToast from './Toast';
|
import VueToast from './Toast';
|
||||||
import { isObject, isServer } from '../utils';
|
import { isObject, isServer } from '../utils';
|
||||||
|
import { removeNode } from '../utils/dom/node';
|
||||||
|
|
||||||
const defaultOptions = {
|
const defaultOptions = {
|
||||||
icon: '',
|
icon: '',
|
||||||
@ -100,11 +101,7 @@ function Toast(options = {}) {
|
|||||||
clearTimeout(toast.timer);
|
clearTimeout(toast.timer);
|
||||||
queue = queue.filter(item => item !== toast);
|
queue = queue.filter(item => item !== toast);
|
||||||
|
|
||||||
const parent = toast.$el.parentNode;
|
removeNode(toast.$el);
|
||||||
if (parent) {
|
|
||||||
parent.removeChild(toast.$el);
|
|
||||||
}
|
|
||||||
|
|
||||||
toast.$destroy();
|
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