diff options
| author | taehoon <th.dev91@gmail.com> | 2019-02-08 11:23:55 -0500 |
|---|---|---|
| committer | taehoon <th.dev91@gmail.com> | 2019-02-15 13:34:33 -0500 |
| commit | 205e38ffa99df67d77290a50b0d318dcc4729b3e (patch) | |
| tree | 54393bf822ae8c815028c7edf97a1eb21c3d52e1 | |
| parent | 09949fc7eea10e592339fd620d140eb92a18e28b (diff) | |
Remove event listener when modal is destroyed
| -rw-r--r-- | src/components/modal/modal.js | 14 |
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) } } |
