fix[ImageCropper]: removeEventListener when destroyed(#2169)

This commit is contained in:
MaYuanhai 2019-05-28 15:10:37 +08:00 committed by Pan
parent 884587cccf
commit 440b5c6596
1 changed files with 10 additions and 6 deletions

View File

@ -839,16 +839,20 @@ export default {
that.$emit('crop-upload-fail', err, field, ki) that.$emit('crop-upload-fail', err, field, ki)
} }
}) })
},
closeHandler(e) {
if (this.value && (e.key == 'Escape' || e.keyCode == 27)) {
this.off()
}
} }
}, },
created() { created() {
// esc // esc
document.addEventListener('keyup', (e) => { document.addEventListener('keyup', this.closeHandler)
if (this.value && (e.key == 'Escape' || e.keyCode == 27)) { },
this.off() destroyed() {
} document.removeEventListener('keyup', this.closeHandler)
}) },
}
} }
</script> </script>