data: {
time:60,
timer: null,
times: 60
},
onLoad: function (options) {
let timer = setInterval(() => {
let temp = this.data.time;
temp--;
this.setData({
time: temp,
timeIntervalID: timer,
},()=>{
if (this.data.time <= 55) {
console.log("tingzhi");
const timeIntervalID = this.data.timeIntervalID
clearInterval(timeIntervalID);
}
});
console.log(temp); // 如果减到0 则清除定时器
}, 1000);
},