Remove event listener when modal is destroyed
This commit is contained in:
parent
09949fc7ee
commit
205e38ffa9
|
@ -3,14 +3,18 @@ const Modal = {
|
||||||
methods: {
|
methods: {
|
||||||
close: function () {
|
close: function () {
|
||||||
this.$emit('close')
|
this.$emit('close')
|
||||||
}
|
},
|
||||||
},
|
handleKeydown: function (e) {
|
||||||
mounted: function () {
|
|
||||||
document.addEventListener('keydown', (e) => {
|
|
||||||
if (this.show && e.keyCode === 27) {
|
if (this.show && e.keyCode === 27) {
|
||||||
this.close()
|
this.close()
|
||||||
}
|
}
|
||||||
})
|
}
|
||||||
|
},
|
||||||
|
mounted: function () {
|
||||||
|
document.addEventListener('keydown', this.handleKeydown)
|
||||||
|
},
|
||||||
|
destroyed: function () {
|
||||||
|
document.removeEventListener('keydown', this.handleKeydown)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue