/**
* 防止重覆点击
* @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()
}
})()
}

原创文章,作者:745907710,如若转载,请注明出处:https://blog.ytso.com/tech/pnotes/267057.html