方法一:简单的60秒倒计时功能,代码如下
@State counter: number = 60
private timerId: number = -1
private changePerSec: number = 1
//启动倒计时
startTimeCounter() {
this.timerId = setInterval(() => {
if (this.counter > 0) {
this.counter -= this.changePerSec
} else {
this.stopTimeCounter()
}
}, 1000) //单位:毫秒
}
//结束倒计时
stopTimeCounter() {
if (this.timerId > 0) {
clearTimeout(this.timerId)
this.timerId = -1
}
}
//页面消失时结束倒计时:必须要有
aboutToDisappear(): void {
this.stopTimeCounter()
}
方法二:30毫秒之后进行操作
setTimeout(() => {
this.isScrolling = false
}, 30)










网友评论