diff --git a/packages/loading/src/directive.js b/packages/loading/src/directive.js index ffda96472..82448fad2 100644 --- a/packages/loading/src/directive.js +++ b/packages/loading/src/directive.js @@ -36,8 +36,7 @@ exports.install = Vue => { }); } else { if (el.domVisible) { - const destroyElement = function() { - el.mask.removeEventListener('transitionend', destroyElement); + el.instance.$on('after-leave', _ => { el.domVisible = false; if (binding.modifiers.fullscreen && el.originalOverflow !== 'hidden') { document.body.style.overflow = el.originalOverflow; @@ -47,8 +46,7 @@ exports.install = Vue => { } else { el.style.position = el.originalPosition; } - }; - el.mask.addEventListener('transitionend', destroyElement); + }); el.instance.visible = false; } } diff --git a/packages/loading/src/index.js b/packages/loading/src/index.js index c5182fb71..7841d0779 100644 --- a/packages/loading/src/index.js +++ b/packages/loading/src/index.js @@ -17,14 +17,6 @@ let fullscreenLoading; LoadingConstructor.prototype.originalPosition = ''; LoadingConstructor.prototype.originalOverflow = ''; -const destroyElement = function() { - this.$el.removeEventListener('transitionend', destroyElement); - this.$el && - this.$el.parentNode && - this.$el.parentNode.removeChild(this.$el); - this.$destroy(); -}; - LoadingConstructor.prototype.close = function() { if (this.fullscreen && this.originalOverflow !== 'hidden') { document.body.style.overflow = this.originalOverflow; @@ -37,7 +29,12 @@ LoadingConstructor.prototype.close = function() { if (this.fullscreen) { fullscreenLoading = undefined; } - this.$el.addEventListener('transitionend', destroyElement.bind(this)); + this.$on('after-leave', _ => { + this.$el && + this.$el.parentNode && + this.$el.parentNode.removeChild(this.$el); + this.$destroy(); + }); this.visible = false; }; diff --git a/packages/loading/src/loading.vue b/packages/loading/src/loading.vue index 9a78483ad..9b7696b48 100644 --- a/packages/loading/src/loading.vue +++ b/packages/loading/src/loading.vue @@ -1,5 +1,5 @@