1、动态设置ref
<el-table-column align="center" prop="saleno" label="销售单号" width="136 ">
<template slot-scope="scope">
<el-input
:ref="`${scope.$index}5`"
v-model="scope.row.saleno"
class="edit-input"
size="small"
@keyup.enter.native="enterMethod(scope.$index, 5)"
/>
</template>
</el-table-column>
enterMethod(rowIndex, key) {
const max = 6;
// 如果,最后一行最后一个框 return
if (rowIndex === this.dataLength - 1 && key === max) return;
// key小于6,在本行内往后挪,key>=6,跳到下一行第一个
let refName = '';
if (key < max) {
refName = `${rowIndex}${key + 1}`;
} else {
if (rowIndex < this.dataLength - 1) {
refName = `${rowIndex + 1}1`;
}
}
// 将焦点移动到下一个输入框
const nextInput = this.$refs[refName];
nextInput.focus();
},