<view class="container">
<image src="../../imgs/swiper1.jpg"></image>
<text bindtap="cliadv">跳过广告 {{miao}}</text>
</view>
.container{
width:100%;
height:100vh;
position: relative;
}
image{
width:100%;
height:100%;
}
text{
position: absolute;
top:10rpx;
right:20rpx;
color:#fff;
}
data: {
miao: 5
},
onLoad: function(options) {
let that = this;
// 在进入页面时开始执行定时器,每秒执行一次miao-1操作。
that.time = setInterval(function() {
that.setData({
miao: that.data.miao - 1
})
// 当miao==0时,清除定时器clearInterval(this.time)(一定要清除定时器),然后自动跳转到首页
if (that.data.miao == 0) {
console.log(that.data.miao)
clearInterval(that.time);
wx.navigateTo({
//保留当前页面,跳转到应用内的某个页面
url: "/pages/index/index"
})
}
}, 1000)
},
cliadv: function() {
clearInterval(this.time)
wx.navigateTo({ //保留当前页面,跳转到应用内的某个页面(最多打开5个页面,之后按钮就没有响应的)
url: "/pages/index/index"
})
},
效果展示
![](https://i-blog.csdnimg.cn/blog_migrate/61b77e7820b72e9f316b3d5ebb223c0b.png)