页面倒计时可以用于,用户没有反应时用,或者开机满屏广告显示
<script>
export default {
data() {
return {
// 倒计时秒数
seconds: 8,
// 定时器的 Id
timer: null
}
},
onLoad() {
this.delayNavigate()
},
methods: {
// 延迟导航到 my 页面
delayNavigate() {
// 把 data 中的秒数重置成 3 秒
this.seconds = 8
// this.showTips(this.seconds)
// 定时器
this.timer = setInterval(() => {
this.seconds--
if (this.seconds <= 0) {
clearInterval(this.timer)
uni.navigateTo({
url: '/pages/index/index'
})
return
}
this.showTips(this.seconds)
}, 1000)
},
// 展示倒计时的提示消息
// showTips(n) {
// 调用 uni.showToast() 方法,展示提示消息
// uni.showToast({
// 不展示任何图标
// icon: 'none',
// 提示的消息
// title: '' + n + ' 秒后自动跳转',
// 为页面添加透明遮罩,防止点击穿透
// mask: true,
// 1.5 秒后自动消失
// duration: 1500
// })
// }
}
}
</script>