Vue中输入框自动获取焦点-移动端ios不能唤起键盘解决办法

Vue中输入框自动获取焦点-移动端ios不能唤起键盘解决办法,第1张

实现自动唤起键盘
方式一(推荐)
this.$nextTick(() => {
	this.$refs.input.focus()
})

方式二
setTimeOut(()=>{
	this.$refs.input.focus()
}, 500)

键盘唤起
延时时间不能过短,因为有页面重新渲染效果,延时时间过短会导致延时不在生效!
该方法在ios中不可用,因为ios为了保护安全,可能会禁止自动获取输入框focus方法

案例 

	
	  
	
	
	  
	  
	
  


// 搜索
searchBtn(k = true) {
  this.isSearchbtn = k;
  this.$nextTick(() => {
	this.$refs.searchtxt.focus();
  });
  // setTimeout(() => {
  //   this.$refs.searchtxt.focus();
  // }, 500);
},

欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/web/996563.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-05-21
下一篇 2022-05-21

发表评论

登录后才能评论

评论列表(0条)

保存