vue-cli2开发的H5移动端,嵌入到app中,问题如下:
1、IOS端,输入框点击时,定位不到,需要多点几次才能获取到焦点
2、手动定位时不灵敏,如上图所示
解决方法:
万能的百度,发现是FastClick导致的,按大佬们的解决方案尝试解决
1、在main.js中引用fastclick的后增加如下代码
import FastClick from 'fastclick'
//FastClick的ios点击穿透解决方案
FastClick.prototype.focus = function (targetElement) {
let length;
if (targetElement.setSelectionRange && targetElement.type.indexOf('date') !== 0 && targetElement.type !== 'time' && targetElement.type !== 'month') {
length = targetElement.value.length;
targetElement.focus(); //增加这一行代码!!!
targetElement.setSelectionRange(length, length);
} else {
targetElement.focus();
}
};
FastClick.attach(document.body)
2、或者在node_modules文件夹下找到fastclick.js做如上修改,这样的好处是再次安装fastclick时防止被覆盖
3、修改之后,发现并没有什么卵用,有大佬说fastclick中并未注册此事件,需去fastclick源代码中进行添加
4、源码里有这些事件,不是这个导致的,最后按照这个大佬的方法解决了IOS端的这个问题,写的非常的详细
https://www.php.cn/js-tutorial-387360.html