鍵盤事件監聽 @keyup.native
@keyup
.native="tdItem.onKeyUp($event, trItem, trIndex)"
(
item , row , index)
.native在父組件中給子組件綁定一個原生的事件,就將子組件變成了普通的HTML標簽
// 獲取所有input
let inputAll = document.querySelectorAll('.table_input input');
// 向上鍵盤 =38
if (
item.keyCode === 38) {
newIndex -= 1;
if (inputAll[newIndex]) {
inputAll[newIndex].focus();
}
}
// 向下鍵盤 =40
if (
item.keyCode === 40) {
newIndex += 1;
if (inputAll[newIndex]) {
inputAll[newIndex].focus();
}
}