前端定时器防抖节流

// 防抖(输入框可用)
debounceFun (fun, time = 300){
clearTimeout(this.debounceTimer)
this.debounceTimer = setTimeout(() => {
fun()
}, time)
},
// 节流
throttleFun (fun, time = 300) {
if (!this.isThrottleWork) {
this.isThrottleWork = true
fun()
this.throttleTimer = setTimeout(() => {
this.isThrottleWork = false
clearTimeout(this.throttleTimer)
}, time)
}
},

 

posted @ 2023-05-09 15:35  fnasklf  阅读(6)  评论(0编辑  收藏  举报