简介:
每一秒出发按一次事件,改变数字
关键代码实现:
var num= 0 ;
data: {
changedata:0
},
timechange:function() {
num +=1;
this.setData({
changedata:num,
});
if (num>5) {
console.log("移除定时器")
this.timer && clearInterval(this.timer);
}
},
clickStart: function() {
console.log("click start");
this.timer = setInterval(function(){
this.timechange()
}.bind(this),1000); // 创建定时器,每个 1s 触发一次 timechange()函数
},