小程序防止连续点击

//app.js内

  globalData: {
    PageActive: true
  },
  preventActive (fn) {
    const self = this
    if (this.globalData.PageActive) {
      this.globalData.PageActive = false
      if (fn) fn()
      setTimeout(() => {
        self.globalData.PageActive = true
      }, 1500); //设置该时间内重复触发只执行第一次,单位ms,按实际设置
    } else {
      console.log('重复点击或触发')
    }
  }

//页面js内执行方法
方法(){
  getApp().preventActive(()=>{
  })
}

 

posted @ 2021-11-05 15:30  ▍凉城空巷°  阅读(185)  评论(0编辑  收藏  举报