其他分享
首页 > 其他分享> > 防止重复点击

防止重复点击

作者:互联网

/**
 * 防止重覆点击
 * @param timer callBack
 * @returns 自执行函数
 */

declare global {
  interface Window {
    lastTime: any
  }
}
export const preventCliks = (callBack: Function, timer: number = 500): void => {
  const _lastTime = window.lastTime || 0
  return ((): void => {
    const nowTime = +new Date()
    if (nowTime - _lastTime > timer || !_lastTime) {
      window.lastTime = nowTime
      callBack()
    }
  })()
}

 

标签:const,重复,nowTime,window,timer,callBack,点击,防止,lastTime
来源: https://www.cnblogs.com/swt-axios/p/16371970.html