看板
This commit is contained in:
@@ -0,0 +1,16 @@
|
||||
export function useThrottle(delay: number = 500) {
|
||||
let previous: number = 0;
|
||||
// 节流函数
|
||||
function throttle(callback: () => void, throttleTime?: number) {
|
||||
throttleTime = throttleTime || delay;
|
||||
let now = Date.now();
|
||||
if (now - previous > throttleTime) {
|
||||
callback();
|
||||
previous = now;
|
||||
}
|
||||
}
|
||||
|
||||
return {
|
||||
throttle
|
||||
};
|
||||
}
|
||||
Reference in New Issue
Block a user