1.text.vue 页面代码
<view class="will-back-after">Will back after<text>{{countdownTime}}s</text></view>
2.data()里面声明countdownTime:
data() {
return {
countdownTime: 5
}
}
3.methods里面写方法:
我这里是倒计时5秒后返回首页。
getCountdownTime() {
this.countdownTime = 5
let timer = setInterval(() => {
this.countdownTime--;
if (this.countdownTime < 1) {
clearInterval(timer)
this.countdownTime = 0
uni.redirectTo({
url: '../../home/home'
})
}
}, 1000)
}
4.进入界面就开始倒计时:
created() {
this.getCountdownTime()
},