首页需要在app.js里面设置一个全局变量用来判断是否终止定时器。(注意这里不是把定时器变量定义成全局的。)
globalData: {
timerLock:false,//是否关闭合成定时器
},
然后在页面上面根据这个timerLock来确定是否关闭定时器
let timer = setInterval(() => {
if(_app.globalData.timerLock){
clearInterval(timer)
}else{
let timestamp = Date.parse(new Date()) / 1000;
(this as any).setData({
nowTime: timestamp,
})
console.log("000000", this.data.nowTime)
}
}, 3000)