鸿蒙开发-按钮倒计时
作者:
激扬飞雪 | 来源:发表于
2024-05-14 22:24 被阅读0次@Entry
@Component
struct CounterCase {
@State count: number = 5
timer: number = -1
flagTimer: boolean = false
build() {
Row() {
Column() {
Button(this.count < 5 ? `还剩下${this.count}秒`:'发送验证码')
.onClick(() => {
if (this.flagTimer) {
return
}
this.flagTimer = true
this.timer = setInterval(() => {
if (this.count == 0) {
clearInterval(this.timer)
this.count = 5
this.flagTimer = false
return;
}
this.count--
}, 1000)
})
}
.width('100%')
}
.height('100%')
}
}
本文标题:鸿蒙开发-按钮倒计时
本文链接:https://www.haomeiwen.com/subject/uwdvjdtx.html
网友评论