plm前端
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 

31 lines
619 B

// 防抖
export function debounce(fn, wait = 3000) {
let timer = null;
return function () {
console.log(wait)
let args = arguments;
let that = this;
if (timer) {
clearTimeout(timer)
}
timer = setTimeout(function () {
timer = null;
fn.apply(that, args)
}, wait)
}
}
// 节流
export function throttle(fn, wait = 3000) {
let timer = null;
return function () {
if (timer != null) return;
let args = arguments;
let that = this;
clearTimeout(timer)
fn.apply(that, args)
timer = setTimeout(function () {
timer = null;
}, wait)
}
}