鍍金池/ 問答/HTML/ 微信小程序定時(shí)器沒一直減只減一次?,求指點(diǎn)

微信小程序定時(shí)器沒一直減只減一次?,求指點(diǎn)

點(diǎn)擊按鈕之后一直是59不減了

data:{
tiem:60
}
code:function () {

var that = this;
var tiem = that.data.tiem;
if (tiem == 0) {
  that.setData({
    tiem: 60,
    true_false: true,
  });
  return;
}
var time = setInterval(function () {
  console.log(tiem-1)
  that.setData({
    true_false: false,
    tiem: tiem -1
  });
}, 1000)

}
clipboard.png

回答
編輯回答
怪痞

number是基本類型。。。tiem沒有引用this.data.tiem

var time = setInterval(function () {
  console.log(this.data.tiem - 1)
  that.setData({
    true_false: false,
    tiem: this.data.tiem - 1
  });
}, 1000)
2018年4月4日 07:10
編輯回答
櫻花霓

tiem得在循環(huán)當(dāng)中再獲取一下

2018年5月17日 06:05
編輯回答
疚幼
var that = this;
var tiem = that.data.tiem;
if (tiem == 0) {
  that.setData({
    tiem: 60,
    true_false: true,
  });
  return;
}
var time = setInterval(function () {
  console.log(that.data.tiem-1)
  that.setData({
    true_false: false,
    tiem: that.data.tiem -1
  });
}, 1000)
2018年7月1日 18:49