收藏
回答

使用定时器进行set数据,为什么模拟器和真机测试的速度不一样?

time:function(index){
    var that = this;
    that.setData({
      now_huihe: 0,
      slow_now_huihe: 0
    })


    var t = setInterval(function () {
      if (that.data.now_huihe == that.data.huihe) {
        clearInterval(t)
        var t2 = setInterval(function () {
          if (that.data.slow_huihe == that.data.slow_now_huihe) {
            if (that.data.index == index) {
              clearInterval(t2)
              
              if (that.data.luckyGoods[index].type==1){
                that.setData({
                  click_cj: false,
                  cj_goods: that.data.luckyGoods[index].name
                })
              }else{
                that.setData({
                  click_cj: false,
                  cj_goods: '恭喜抽中' + that.data.luckyGoods[index].name,
                  cj_select:true,
                  zhe: true
                })
              }
              app.getUserInfoFromServer()
            } else {
              that.slow()
            }
          } else {
            that.slow()
          }
        }, 500)
      } else {
        that.quick()
      }
    }, that.data.time)
  },
  quick: function() {
    var that = this;
    if (that.data.index == 8) {
      that.setData({
        index: -1,
        now_huihe: that.data.now_huihe + 1
      })
    }
    that.setData({
      index: that.data.index + 1
    })
  },
  slow: function() {
    var that = this;
    if (that.data.index == 8) {
      that.setData({
        index: -1,
        slow_now_huihe: that.data.slow_now_huihe + 1
      })
    }
    that.setData({
      index: that.data.index + 1
    })
  },



模拟器上能快速的 0.1秒 变一次数据,
然后变成0.5秒
到真机模拟上会变得非常慢,最少1s 变一次
最后一次编辑于  2020-04-11
回答关注问题邀请回答
收藏
登录 后发表内容
问题标签