fastclick 的安装
npm install fastclick --save
在main.js中引入
import FastClick from "fastclick"
//fastclick导致input框点击慢的问题,引入
import "@utils/resetFastClick.js
FastClick.attach(document.body)
在utils文件夹中创建resetFastClick.js文件
import FastClick from "fastclick"
//fastclick 在 iOS 下 input框点击慢的问题,引入
import "@utils/resetFastClick.js
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()
}
}
如果使用了ts,还要安装@types/fastclick
npm i @types/fastclick
如果是vue3中使用,引入如下
FastClick(document.body)