startCountdown() {
let that = this; // 保存this引用
this.setData({
timer: setInterval(() => {
let currentCountdown = that.data.countdown - 1;
that.setData({
countdown: currentCountdown
});
if (currentCountdown <= 0) {
console.log("倒计时结束");
wx.exitMiniProgram({
success: (res) => {
console.log("退出小程序");
},
fail: (err) => {
console.log("退出小程序失败", err);
}
});
clearInterval(that.data.timer);
// 倒计时结束后的操作
}
}, 1000)
});
},
不支持延时关闭。