学无先后,达者为师

网站首页 编程语言 正文

element组件autofocus( 自动获取焦点)失效

作者:大大。 更新时间: 2023-10-16 编程语言

 如果加了autofocus还是无效,那么可以用以下方法

 <el-input
    v-model="patientId"
    placeholder=""
autofocus
    ref="input1"
></el-input>

注意如果使用ref使用动态id,那么 :ref="id"
 // 在需要获取焦点的地方
  var that = this;
      this.$nextTick(() => {
        that.$refs['input1'].focus();
      });


如果refs使用动态的id,那么修改为that.$refs[id].focus();

下面是我使用时代码 

<div >
        <el-input v-if="scope.row.ModelSquare==true" @blur="ModelSquareClose(scope.$index,scope.row.id,scope.row.square)" v-model="scope.row.square" class="inp_dz" autofocus=true :ref="scope.row.id" size=small>
                    <span slot="suffix" class="span_suf">㎡</span>
                  </el-input>
                  <i v-else class="el-icon-edit-outline blue_color" @click="ModelSquareEdit(scope.$index,scope.row.id)"></i>
                </div>
 ModelSquareEdit(index, id) {
      //input出现
      console.log(id, 'id');
      if (this.AuditList.length > 0) {
        this.AuditList[index].ModelSquare = true;
      }
      // this.AuditQuoteList[index1].list[index2].ModelCheck2 = true;

      this.$forceUpdate();

      if (this.timer2) {
        clearTimeout(this.timer2);
      }
      var that = this;
      this.$nextTick(() => {
        that.$refs[id].focus();
      });
    },
    ModelSquareClose(index, id, square) {
      //input消失关闭  
      if (this.AuditList.length > 0) {
        this.AuditList[index].ModelSquare = false;
      }
      if (square) {
        this.updateSquareClick(id, square);
      } else {
        this.get_audit_detail();
      }

      this.$forceUpdate();
    },

原文链接:https://blog.csdn.net/weixin_43923808/article/details/131222634

  • 上一篇:没有了
  • 下一篇:没有了
栏目分类
最近更新