CNCEC_APP/uni_modules/uview-pro/libs/hooks/useThrottle.ts

17 lines
399 B
TypeScript
Raw Normal View History

2026-03-25 14:54:15 +08:00
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
};
}