From a0793dbeab6eac29863ad9aef7de77710600bb37 Mon Sep 17 00:00:00 2001 From: MaYuanhai <414199639@qq.com> Date: Tue, 28 May 2019 15:10:37 +0800 Subject: [PATCH] fix[ImageCropper]: removeEventListener when destroyed(#2169) --- src/components/ImageCropper/index.vue | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/src/components/ImageCropper/index.vue b/src/components/ImageCropper/index.vue index c30c5b18..c2688e99 100644 --- a/src/components/ImageCropper/index.vue +++ b/src/components/ImageCropper/index.vue @@ -839,16 +839,20 @@ export default { that.$emit('crop-upload-fail', err, field, ki) } }) + }, + closeHandler(e) { + if (this.value && (e.key == 'Escape' || e.keyCode == 27)) { + this.off() + } } }, created() { // 绑定按键esc隐藏此插件事件 - document.addEventListener('keyup', (e) => { - if (this.value && (e.key == 'Escape' || e.keyCode == 27)) { - this.off() - } - }) - } + document.addEventListener('keyup', this.closeHandler) + }, + destroyed() { + document.removeEventListener('keyup', this.closeHandler) + }, }