Skip to content

Commit dac3abc

Browse files
committed
cleanup element before destroy
1 parent 2756dec commit dac3abc

File tree

1 file changed

+20
-14
lines changed

1 file changed

+20
-14
lines changed

src/components/mdSnackbar/mdSnackbar.vue

Lines changed: 20 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,9 @@
5050
}
5151
},
5252
methods: {
53+
removeElement() {
54+
this.rootElement.removeChild(this.snackbarElement);
55+
},
5356
open() {
5457
if (manager.current) {
5558
manager.current.close();
@@ -63,21 +66,23 @@
6366
this.closeTimeout = window.setTimeout(this.close, this.mdDuration);
6467
},
6568
close() {
66-
const removeElement = () => {
67-
this.$refs.container.removeEventListener(transitionEndEventName, removeElement);
69+
if (this.$refs.container) {
70+
const removeElement = () => {
71+
this.$refs.container.removeEventListener(transitionEndEventName, removeElement);
6872
69-
if (this.rootElement.contains(this.snackbarElement)) {
70-
this.snackbarElement.querySelector('.md-ripple').classList.remove('md-active');
71-
this.rootElement.removeChild(this.snackbarElement);
72-
}
73-
};
73+
if (this.rootElement.contains(this.snackbarElement)) {
74+
this.snackbarElement.querySelector('.md-ripple').classList.remove('md-active');
75+
this.removeElement();
76+
}
77+
};
7478
75-
manager.current = null;
76-
this.active = false;
77-
this.$emit('close');
78-
this.$refs.container.removeEventListener(transitionEndEventName, removeElement);
79-
this.$refs.container.addEventListener(transitionEndEventName, removeElement);
80-
window.clearTimeout(this.closeTimeout);
79+
manager.current = null;
80+
this.active = false;
81+
this.$emit('close');
82+
this.$refs.container.removeEventListener(transitionEndEventName, removeElement);
83+
this.$refs.container.addEventListener(transitionEndEventName, removeElement);
84+
window.clearTimeout(this.closeTimeout);
85+
}
8186
}
8287
},
8388
mounted() {
@@ -88,7 +93,8 @@
8893
});
8994
},
9095
beforeDestroy() {
91-
this.close();
96+
window.clearTimeout(this.closeTimeout);
97+
this.removeElement();
9298
}
9399
};
94100
</script>

0 commit comments

Comments
 (0)