Onlife/common/preventReClick.js

20 lines
403 B
JavaScript
Raw Normal View History

2025-04-19 15:38:48 +08:00
//在preventReClick.js中封装防抖方法
export const Debounce = (fn, wait) => {
let delay = wait|| 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)
}
}