data: {
timer: null
},
timer() {
this.setData({
timer: setInterval(() => {
console.log(222222222)
}, 1000)
})
},
onUnload(){
clearInterval(this.data.timer);
},
onHide(){
clearInterval(this.data.timer);
},
onLoad(){
this.timer()
}
这种方式也试了 还是不行
var timer; //页面顶部定义
onUnload(){
clearInterval(this.timer);
},
onHide(){
clearInterval(this.timer);
},
onLoad: function(options) {
var that = this;
this.timer=setInterval(() => {
console.log(222222222)
}, 1000)
}
// 什么时候用this和this.data,看来你完全不清楚。。 Page({ data: { timer: null }, onUnload(){ clearInterval(this.data.timer); }, onHide(){ clearInterval(this.data.timer); }, onLoad(){ this.data.timer = setInterval(() => { console.log(222222222) }, 1000) } }) -------------------------------------------- var timer //页面顶部定义 Page({ onUnload(){ clearInterval(timer); }, onHide(){ clearInterval(timer); }, onLoad(options) { timer = setInterval(() => { console.log(222222222) }, 1000) } }) -------------------------------------------- Page({ onUnload(){ clearInterval(this.timer) }, onHide(){ clearInterval(this.timer) }, onLoad(options) { this.timer = setInterval(() => { console.log(222222222) }, 1000) } })
我把这个关掉就好了~