绑定键盘事件
<i class="el-icon-d-arrow-left" @keyup.right.native="goUp" />
注册全局键盘事件
window.addEventListener('keyup', this.handleKeyup)
handleKeyup(event) {//event键盘ASCII 码,键盘事件触发
if (event.keyCode === 37) {
this.goUp()//调用方法
} else if (event.keyCode === 39) {
this.goDown()
} else {
return
}
},
goUp() {
const that = this
const index = that.imgFileArray.findIndex((profile) => profile.fileUrl === that.previewImgObj.fileUrl)
if (index > 0) {
that.previewImgObj = that.imgFileArray[index - 1]
}
},
goDown() {
const that = this
const index = that.imgFileArray.findIndex((profile) => profile.fileUrl === that.previewImgObj.fileUrl)
if (index < that.imgFileArray.length - 1) {
that.previewImgObj = that.imgFileArray[index + 1]
}
},