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

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

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

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

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

<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();
      }
    }

 

posted @ 2019-03-11 15:46  甜土豆  阅读(4569)  评论(1编辑  收藏  举报