22.线上开启调试模式调试bug

线上会碰到无法重现的bug,所以有时需要用户打开调试模式
需求:点击页面中某按钮5次,循环出现调试模式
1.utils/showDebug.js

//点击5次循环出现调试模式和关闭调试模式
export default class ShowDebug {
  constructor(maxTime = 5) {
    this.maxTime = maxTime; //需点击按钮的次数
    this.time = 0; //点击的次数
    this.show = false; //是否展示debug模式
  }
  //展示debug模式
  showDebug() {
    var that = this;
    wx.setEnableDebug({
      enableDebug: !that.show,
    });
    that.show = !that.show;
  }
  //判断是否达到次数
  judge() {
    var that = this;
    //判断是否达到次数
    if (this.time >= this.maxTime) {
      that.showDebug();
      this.time = 0;
    } else {
      this.time += 1;
    }
  }
}

2.在index.js中使用

  import ShowDebug from '../../utils/showDebug';
  onLoad: function() {
    this.showDebug = new ShowDebug(3);
  },
  //点击事件
  onShowDebug() {
    var that = this;
    this.showDebug.judge(); //判断是否出现调试模式
  },

你可能感兴趣的:(22.线上开启调试模式调试bug)