he wei
2025-04-03 c6a2d2debf161b987ff91c6ac9560d10fc98c54b
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
// 节流
export const throttle = function (fn, delay = 300) {
  var lastTime, timer;
  return function () {
    var _this = this;
    var args = arguments;
    var nowTime = Date.now();
    if (lastTime && nowTime - lastTime < delay) {
      if (timer) clearTimeout(timer);
      timer = setTimeout(function () {
        lastTime = nowTime;
        fn.apply(_this, args);
      }, delay);
    } else {
      lastTime = nowTime;
      fn.apply(_this, args);
    }
  };
};