[Vue2] element 获取el-input焦点

文章讲述了如何在VueElementUI的el-popover弹出时,确保关联的el-input自动获得焦点。作者提到需在el-popover的show事件上绑定聚焦逻辑,通过`this.$refs.inputFocus.focus()`实现。
摘要由CSDN通过智能技术生成


需求:如图,需要在点开el-popover的时候自动聚焦到输入框中。

​​
对于input获取焦点,element官网:

方法:el-input上绑定ref ,但是和el-popover联动,必须在el-popover的show上绑定

<el-popover @show="handleFocus" placement="bottom" width="300" v-model="visiblePerson" trigger="click" >
    <el-input ref="inputFocus" v-model="personKeyWord" @input="remotePerson(personKeyWord, personList, personOption)"  placeholder="输入关键字查询"  prefix-icon="el-icon-search" ></el-input>
</el-popover>
handleFocus() {
   this.$nextTick((_) => {
       this.$refs.inputFocus&&this.$refs.inputFocus.focus();
    })
},

最开始我监控el-popover的值为true,不行,还是得绑定在show的方法里。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值