ios移动端input输入框卡顿,失焦,弹不出软键盘

当前是个vue项目,我之前在项目引入fastclick,导致出现了ios移动端input输入框卡顿,失焦,弹不出软键盘
因此可在main.js文件做修改

//---------------原来引入
import FastClick from 'fastclick'
FastClick.attach(document.body);

//-------------现在修改-----------------
//原fastclick视为了解决页面迟钝,现解决fastclick带来引入后导致输入框失焦,
FastClick.prototype.focus = function (targetElement) {
  var length;

  var deviceIsWindowsPhone = navigator.userAgent.indexOf("Windows Phone") >= 0;
  var deviceIsIOS = /iP(ad|hone|od)/.test(navigator.userAgent) && !deviceIsWindowsPhone;  
    //兼容处理:在iOS7中,有一些元素(如date、datetime、month等)在setSelectionRange会出现TypeError    
    //这是因为这些元素并没有selectionStart和selectionEnd的整型数字属性,所以一旦引用就会报错,因此排除这些属性才使用setSelectionRange方法
  if ( deviceIsIOS && targetElement.setSelectionRange && targetElement.type.indexOf('date') !== 0 && targetElement.type !== 'time' && targetElement.type !== 'month' && targetElement.type !== 'email') { 
    length = targetElement.value.length; 
    targetElement.setSelectionRange(length, length);//修复bug ios 11.3不弹出键盘,这里加上聚焦代码,让其强制聚焦弹出键盘    
    targetElement.focus(); 
  } else { 
    targetElement.focus(); 
  }
}

版权声明:本文为qiumen原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接和本声明。