Skip to content

Commit

Permalink
fix[ImageCropper]: removeEventListener when destroyed(PanJiaChen#2169)
Browse files Browse the repository at this point in the history
  • Loading branch information
mayunhai authored and PanJiaChen committed May 28, 2019
1 parent 9538d1b commit a0793db
Showing 1 changed file with 10 additions and 6 deletions.
16 changes: 10 additions & 6 deletions src/components/ImageCropper/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -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)
},
}
</script>

Expand Down

0 comments on commit a0793db

Please sign in to comment.