在开发过程中遇到这样一个问题,利用PDA
扫码,扫码后文本框的焦点会自动失焦,但是又想让自动获取焦点连续扫码,那该如何做呢?请往下看:
也许大部分同学和我一样都会这么做,一直修改文本框属性focus
为true
,但是没有效果,参考如下
<view class="" style="display: inline-block; width: 80%;">
<input
v-model="barCode"
@blur="shiquBlur()"
@confirm="getScanValue()"
:showAction="false"
:focus="focusShow"
id="bar_name"
class="barInput"
:placeholder="placeholderValue"
:animation="false"></input>
</view>
focusShow: true
尝试手动实现,调用focus
事件,想到它可不像之前的h5
项目,是没有操作dom
的方法,所以暂时搁置,在网上找了解决方案都不合适
最后理清了一下思路得使focus
的状态更新才能生效,添加了onblur
事件
shiquBlur() {
let that = this
that.focusShow = false // 这个代码是关键!!!!
that.$nextTick(() => {
that.focusShow = true
})
that.$forceUpdate()
},