标签:方案 false rip ges last als log dex date()
<view bindtap="loadMulti">
    <text>连续点击,加载多次</text>
</view>
<view bindtap="loadOnce">
    <text>连续点击,加载一次</text>
</view>
loadMulti:function(e) {
    wx.navigateTo({
        url: ‘/pages/loadMulti/index‘,
    })
},
  loadOnce:function(e) {
    if (!this.pageLoading) {
      this.pageLoading = !0;
      wx.navigateTo({
        url: ‘/pages/loadOnce/index‘,
      })
    }
  },
 
  onShow: function() {
    this.pageLoading = !1;
}
function throttle(fn, gapTime) {
    if (gapTime == null || gapTime == undefined) {
        gapTime = 1500
    }
    let _lastTime = null
    // 返回新的函数
    return function () {
        let _nowTime = + new Date()
        if (_nowTime - _lastTime > gapTime || !_lastTime) {
            fn.apply(this, arguments)   //将this和参数传给原函数
            _lastTime = _nowTime
        }
    }
}
<button bindtap=‘tap‘ data-key=‘abc‘>tap</button>
const util = require(‘../../utils/util.js‘)
Page({
    data: {
        text: ‘tomfriwel‘
    },
    onLoad: function (options) {
    },
    tap: util.throttle(function (e) {
        console.log(this)
        console.log(e)
        console.log((new Date()).getSeconds())
    }, 1000)
})
标签:方案 false rip ges last als log dex date()
原文地址:https://www.cnblogs.com/bgwhite/p/9455744.html