

监听键盘事件
window.addEventListener("keyup", this.handleKeyup);
主要方法
handleKeyup() {
const e = event||window.event||arguments.callee.caller.arguments[0];
var selectindex = this.sampleList.findIndex((i) => {
return this.selectSample.id == i.id;
});
if (e && e.keyCode == 38 && selectindex > 0) {
this.$refs.singleTable.setCurrentRow(
this.sampleList[selectindex - 1]
);
this.times = setTimeout(() => {
clearTimeout(this.times);
}, 300);
}
}
if (e && e.keyCode== 40 && selectindex < this.sampleList.length - 1){
this.$refs.singleTable.setCurrentRow(
this.sampleList[selectindex + 1]
);
this.times = setTimeout(() => {
clearTimeout(this.times);
}, 300);
}
}
关闭页面销毁
destroyed() {
window.removeEventListener("keyup", this.handleKeyup);
},