连续点击按钮跳页面重复

https://www.jianshu.com/p/12c7307a02c2

    if (gapTime == null || gapTime == undefined) {
      gapTime = 1500
    }
    let _lastTime = null
    return function () {
      let _nowTime = + new Date()
        if (_nowTime - _lastTime > gapTime || !_lastTime) {
            fn()
            _lastTime = _nowTime
        }
    }
}
 module.exports = {
  throttle: throttle
}

下面的更好

unction throttle(fn,gapTime) {
    if (gapTime == null || gapTime == undefined) {
      gapTime = 1500
    }
    let _lastTime = null
    return function () {
      let _nowTime = + new Date()
        if (_nowTime - _lastTime > gapTime || !_lastTime) {
            // 将this和参数传给原函数
            fn.apply(this,arguments)
            _lastTime = _nowTime
        }
    }
}

 

posted @ 2020-01-02 16:07  ThisCall  阅读(207)  评论(0编辑  收藏  举报