vue Antd 输入框Input自动聚焦

1、从vue的实例属性$ref去调input的focus方法使其实现聚焦。

<a-input type="text ref="ainput" /> 
<button @click="handleChange"></button>

2、点击button自动聚焦,或其他事件需要聚焦

methods:{
    handleChange(){
        this.$nextTick(()=>{
            this.$refs.ainput.focus()
        })
    }
}

vue中输入框聚焦,自动跳转下一个输入框

需求 

点击请扫描库位,enter键触发后,跳转到下一输入框,然后自动聚焦另外一个输入框上

在这里插入图片描述

 <el-input
        v-model="posName"  clearable size="small" placeholder="请扫描库位" style="width: 200px"
        class="filter-item"  @keyup.enter.native="jumpInput"
      />
  <el-input
        ref="barcodeMsg" v-model="barcode" clearable size="small"  placeholder="请扫描物料信息"
        style="width: 400px"  class="filter-item" @keyup.enter.native="getSearch('material')"
      />
 // enter键触发
    jumpInput() {
      this.$refs.barcodeMsg.focus(); // 自动获取焦点
    },

如图

在这里插入图片描述

总结