throttle.js 429 B

1234567891011121314151617181920
  1. const throttle = function(func, duration) {
  2. let start = 0
  3. return function() {
  4. let that = this
  5. let now = Date.now();
  6. if (now - start > duration) {
  7. func.apply(that, arguments);
  8. start = now
  9. } else {
  10. // wx.showToast({
  11. // title: `您的操作太频繁啦,请在${Math.ceil(duration/1000)}秒后再试哦~`,
  12. // icon: 'none'
  13. // })
  14. }
  15. }
  16. }
  17. module.exports = {
  18. throttle
  19. }