定时器Timer
定义图片定时播放 @State showSwiper: boolean = false; private timer = null; setTimeout(() => {//三秒后播放图片 this.showSwiper = true; this.startTiming(); }, Const.SPLASH_DURATION); } startTiming() {//播放五秒图片 th
·
定义图片定时播放
@State showSwiper: boolean = false;
private timer = null;
setTimeout(() => {//三秒后播放图片
this.showSwiper = true;
this.startTiming();
}, Const.SPLASH_DURATION);
}
startTiming() {//播放五秒图片
this.timer = setInterval(() => {
this.countdown--;
if (this.countdown === 0) {
this.clearTiming();
//五秒后跳转到首页
this.jumpToMainPage();
}
}, Const.DURATION);
}
clearTiming() {//清理定时器
if (this.timer !== null) {
clearInterval(this.timer);
this.timer = null;
}
}
jumpToMainPage() {//跳转到应用首页
this.clearTiming();
router.replaceUrl({
url: 'pages/MainPage'
});
}
aboutToDisappear() {//页面销毁时清理定时器
this.clearTiming();
}
定时器形式
xxx(()=>{
xxx
},设定时间)
更多推荐
已为社区贡献22条内容
所有评论(0)