// 防抖
export const antiShake= (fn, t) => {
let delay = t || 500
let timer
return function () {
let args = arguments;
if (timer) {
clearTimeout(timer)
}
let callNow = !timer
timer = setTimeout(() => {
timer = null
}, delay)
if (callNow) fn.apply(this, args)
}
}
创建一个js文件写入如上代码
在需要使用的界面引入,哪个方法需要使用
import { antiShake } from "../utils/base";
//例如点击事件使用
clickSure: antiShake(function () {
console("xx")
},1000),