fix(custom): \!
All checks were successful
continuous-integration/drone/push Build is passing

This commit is contained in:
2024-09-23 20:43:11 +08:00
parent b5361277ca
commit 097029128c
2 changed files with 38 additions and 13 deletions

View File

@@ -83,3 +83,29 @@ export function showTips(msg: string) {
icon: 'none',
});
}
// 防抖函数
export function debounce(fn: Function, delay: number = 500) {
let timer: any = null;
return function (...args: any[]) {
if (timer) {
clearTimeout(timer);
}
timer = setTimeout(() => {
fn.apply(this, args);
}, delay);
};
}
// 节流函数
export function throttle(fn: Function, delay: number) {
let timer: any = null;
return function (...args: any[]) {
if (!timer) {
timer = setTimeout(() => {
fn.apply(this, args);
timer = null;
}, delay);
}
};
}