element table 实现input输入框回车键跳入下一行,自动获取焦点

element table 实现input输入框回车键跳入下一行,自动获取焦点数组

使用动态绑定ref  this.$refs获取的是一个全部id组成的对象。this

使用Object.keys(this.$refs) //遍历这个对象,返回的是一个包含全部id组成的一个数组,让当前的index+1获取到下一个input的id.spa

再根据这个id 使用this.$refs获取到这个input 使用focuscode

<template slot-scope="scope">
                <el-input class="year-leiji" :ref='scope.row.id' autocomplete="off" v-model.number="scope.row.ljje" @keydown.native="validateCounts(scope.row,scope.$index, $event)"
                ></el-input>
              </template>

 

 validateCounts(row,index, e) { const val = e.target.value; var keyCode = e.keyCode || e.which || e.charCode; if(keyCode=== 13) { this.submitYearLeiJi(row.id, val) this.$refs[row.id].blur() if(Object.keys(this.$refs).length-1 === index) { index = -1 } this.$refs[Object.keys(this.$refs)[index + 1]].focus(); } }
相关文章
相关标签/搜索