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(); } }
相關文章
相關標籤/搜索