mirror of
https://gitee.com/TSpecific/tuniao-ui.git
synced 2026-06-08 20:43:17 +08:00
c6bbf0a829
Signed-off-by: wssam <573616439@qq.com>
28 lines
496 B
JavaScript
28 lines
496 B
JavaScript
//防抖
|
|
export function debounceFun(func, delay=500) {
|
|
//定时器
|
|
let timer;
|
|
return function(...args) {
|
|
// 清除之前设置的定时器
|
|
clearTimeout(timer);
|
|
timer = setTimeout(() => {
|
|
func.apply(this, args);
|
|
}, delay);
|
|
};
|
|
}
|
|
|
|
//节流
|
|
export function throttleFun(func, delay=500) {
|
|
//定时器
|
|
let timer = null;
|
|
return function(...args) {
|
|
if(!timer){
|
|
timer = setTimeout(() => {
|
|
//执行前清空
|
|
timer = null;
|
|
func.apply(this, args);
|
|
}, delay);
|
|
}
|
|
};
|
|
}
|