wanyu_frontend/utils/throttle.js

17 lines
317 B
JavaScript

//节流函数
export function throttle(fn, gapTime = 1500) {
let lastTime = 0;
return function () {
const nowTime = Date.now();
if (nowTime - lastTime >= gapTime) {
lastTime = nowTime;
fn.apply(this, arguments);
}
};
}
module.exports = {
throttle
};