1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
| /**
| * 防抖函数
| * @param fn 函数
| * @param delay 延迟时间
| * @returns
| */
| const debounce = <T extends (...args: any[]) => any>(fn: T, delay: number) => {
| let timer: number | null = null;
| return function (this: any, ...args: Parameters<T>) {
| if (timer) clearTimeout(timer);
| timer = setTimeout(() => {
| fn.apply(this, args);
| }, delay);
| };
| };
|
| export { debounce };
|
|