Newer
Older
xc-business-system / src / utils / debounce.ts
dutingting on 22 Jan 2024 362 bytes bug修复与新需求功能开发
// 防抖
// 不管怎么点击,只在delay毫秒后触发事件,delay毫秒内点击也要等到delay毫秒后再触发事件
export const debounce = (fn: Function, delay = 2000) => {
  let timer: any = null
  return (...args: any[]) => {
    if (timer) {
      clearTimeout(timer)
    }
    timer = setTimeout(() => {
      fn(...args)
    }, delay)
  }
}