Remove event listener when modal is destroyed

This commit is contained in:
taehoon 2019-02-08 11:23:55 -05:00
parent 09949fc7ee
commit 205e38ffa9

View file

@ -3,14 +3,18 @@ const Modal = {
methods: {
close: function () {
this.$emit('close')
}
},
mounted: function () {
document.addEventListener('keydown', (e) => {
handleKeydown: function (e) {
if (this.show && e.keyCode === 27) {
this.close()
}
})
}
},
mounted: function () {
document.addEventListener('keydown', this.handleKeydown)
},
destroyed: function () {
document.removeEventListener('keydown', this.handleKeydown)
}
}