Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
1.8k views
in Technique[技术] by (71.8m points)

vue使用v-show隐藏input框后不再能聚焦

v-show应该是有加载的呀,实在想不明白;现在需求就是点击这个id为item9的DIV就去获取input框焦点,可是v-show="false"后就没有反应的,要是有显示的话一切都是跑的通的
HTML代码:

<div id="item9" class="memuModule" @click="clickToFocus()">
</div>  
<div v-show="true">
  <input v-model="codeTemp" autofocus ref="alwaysFocus"      @change="searchEnterFun"></input> 
</div>  

JS代码:
//change事件截取二维码

searchEnterFun(){
  var dataEn = this.codeTemp.split(":")
  console.log(dataEn)
},

//对焦input框以填写健康码

clickToFocus(){
  this.$nextTick(() => {
    this.$refs.alwaysFocus.focus()
  })
},

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

v-show 的话,就被隐藏了,不存在与页面中了。

你应该考虑如何让他看不见,但是还存在于页面中

  1. opacity
  2. width:0;height:0
  3. position:fixed;left:-999px;top: -999px

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...