Skip to content

Commit e130821

Browse files
author
Pooya Parsa
committed
call removeEventListener after destroy
1 parent 6118082 commit e130821

File tree

2 files changed

+23
-12
lines changed

2 files changed

+23
-12
lines changed

components/dropdown.vue

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
:disabled="disabled">
1212
<slot name="text">
1313
{{text}}
14+
1415
</slot>
1516
</b-button>
1617

@@ -78,6 +79,11 @@
7879
document.documentElement.addEventListener('click', this.clickOut);
7980
}
8081
},
82+
destroyed() {
83+
if (typeof document !== 'undefined') {
84+
document.removeEventListener('click', this.clickOut);
85+
}
86+
},
8187
created() {
8288
this.$root.$on('shown::dropdown', el => {
8389
if (el !== this) {

components/nav-item-dropdown.vue

Lines changed: 17 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,23 @@
4949
},
5050
class: ['class']
5151
},
52+
created() {
53+
this.$root.$on('shown::dropdown', el => {
54+
if (el !== this) {
55+
this.clickOut();
56+
}
57+
});
58+
},
59+
mounted() {
60+
if (typeof document !== 'undefined') {
61+
document.documentElement.addEventListener('click', this.clickOut);
62+
}
63+
},
64+
destroyed() {
65+
if (typeof document !== 'undefined') {
66+
document.removeEventListener('click', this.clickOut);
67+
}
68+
},
5269
methods: {
5370
setShow(state) {
5471
if (this.show === state) {
@@ -69,17 +86,5 @@
6986
this.setShow(false);
7087
}
7188
},
72-
created() {
73-
this.$root.$on('shown::dropdown', el => {
74-
if (el !== this) {
75-
this.clickOut();
76-
}
77-
});
78-
},
79-
mounted() {
80-
if (typeof document !== 'undefined') {
81-
document.documentElement.addEventListener('click', this.clickOut);
82-
}
83-
}
8489
};
8590
</script>

0 commit comments

Comments
 (0)