Welcome to OGeek Q&A 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 Reply

0 votes
by (71.8m points)

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

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

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

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

1.4m articles

1.4m replys

5 comments

57.0k users

...