小程序防止点击重复导致数据错乱

  // 节流函数 防止重复点击

  throttle(fn, info, gapTime) {

    let _nowTime = new Date().getTime()

    if (_nowTime - this._lastTime > gapTime || !this._lastTime) {

      if (fn == 'add') {

        this.fn_add(info.e, info.index,)

      } else if (fn == 'reduce') {

        this.fn_reduce(info.e,info.index)

      }

      this._lastTime = _nowTime

    }

  }

//数量+  

add(e, index) {

    let a = { e, index,}

    this.throttle('add', a, 500)

  }

    //增加数量

    fn_add(e,index){

//逻辑处理

}

©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。