Newer
Older
jh-business-system / src / utils / debounce.ts
dutingting 29 days ago 362 bytes Initial commit: 项目初始化
// 防抖
// 不管怎么点击,只在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)
  }
}