xiugai
This commit is contained in:
@ -5,7 +5,8 @@ Page({
|
||||
* 页面的初始数据
|
||||
*/
|
||||
data: {
|
||||
|
||||
countdown: 60, // 设置倒计时时长(秒)
|
||||
timer: null, // 存储计时器
|
||||
},
|
||||
|
||||
name(e){
|
||||
@ -76,6 +77,34 @@ Page({
|
||||
console.error('请求失败', err);
|
||||
}
|
||||
});
|
||||
this.startCountdown();
|
||||
},
|
||||
startCountdown() {
|
||||
this.setData({
|
||||
isCountingDown: true,
|
||||
countdown: 60
|
||||
});
|
||||
|
||||
this.data.timer = setInterval(() => {
|
||||
let count = this.data.countdown;
|
||||
if (count <= 1) {
|
||||
clearInterval(this.data.timer);
|
||||
this.setData({
|
||||
isCountingDown: false,
|
||||
countdown: 60
|
||||
});
|
||||
} else {
|
||||
this.setData({
|
||||
countdown: count - 1
|
||||
});
|
||||
}
|
||||
}, 1000);
|
||||
},
|
||||
onUnload() {
|
||||
// 页面卸载时清除定时器
|
||||
if (this.data.timer) {
|
||||
clearInterval(this.data.timer);
|
||||
}
|
||||
},
|
||||
// 注册
|
||||
submit(){
|
||||
@ -161,6 +190,7 @@ Page({
|
||||
icon: 'error',
|
||||
duration: 2000
|
||||
});
|
||||
|
||||
}
|
||||
},
|
||||
fail(err) {
|
||||
|
Reference in New Issue
Block a user