Skip to content

Commit 6e1e9c3

Browse files
committed
feat: [debounce] 增加防抖函数至工具包
1 parent 9cc5df1 commit 6e1e9c3

File tree

1 file changed

+3
-17
lines changed

1 file changed

+3
-17
lines changed

src/tools/other.ts

Lines changed: 3 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import debounce from 'debounce'
12
/**
23
* @description 获取文件类型
34
* @param url 文件地址
@@ -51,22 +52,6 @@ export function randomString(length: number): string {
5152
return result
5253
}
5354

54-
/**
55-
* @description 防抖函数
56-
* @param func 函数
57-
* @param delay 延迟时间
58-
* @returns { Function } Function:防抖函数
59-
*/
60-
export function debounce(func: Function, delay: number): Function {
61-
let timer: NodeJS.Timeout
62-
return function (this: any, ...args: any[]) {
63-
clearTimeout(timer)
64-
timer = setTimeout(() => {
65-
func.apply(this, args)
66-
}, delay)
67-
}
68-
}
69-
7055
/**
7156
* @description 节流函数
7257
* @param func 函数
@@ -93,10 +78,11 @@ export function throttle(func: Function, delay: number): Function {
9378
}
9479
}
9580

81+
export { debounce }
82+
9683
export default {
9784
getFileType,
9885
formatNumber,
9986
randomString,
100-
debounce,
10187
throttle,
10288
}

0 commit comments

Comments
 (0)