aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authortaehoon <th.dev91@gmail.com>2019-02-08 11:23:55 -0500
committertaehoon <th.dev91@gmail.com>2019-02-15 13:34:33 -0500
commit205e38ffa99df67d77290a50b0d318dcc4729b3e (patch)
tree54393bf822ae8c815028c7edf97a1eb21c3d52e1 /src
parent09949fc7eea10e592339fd620d140eb92a18e28b (diff)
Remove event listener when modal is destroyed
Diffstat (limited to 'src')
-rw-r--r--src/components/modal/modal.js14
1 files changed, 9 insertions, 5 deletions
diff --git a/src/components/modal/modal.js b/src/components/modal/modal.js
index 36cd7f4a..963f4bcd 100644
--- a/src/components/modal/modal.js
+++ b/src/components/modal/modal.js
@@ -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)
}
}