app.js:
App({
onLaunch(){
},
globalData:{
time:1,
timel:2
}
})
index.js:
// index.js
Page({
data:{
push:[],
showAd:true
},
// 请求接口
getList:function () {
var that=this;
wx.request({
// 接口
url: app.globalData.URL+'api/activity/list',
method:"POST",
data:{},
success: function success(res) {
if(res.data.rows.length>0){
that.setData({
push: res.data.rows,
showAd: false
})
}
},fail: function fail(error) {
console.log(error,'失败')
}
})
},
// 请求接口
onLoad:function(){
var that = this;
// that.getList()这个请求接口改成了放在定时器里触发
if(app.globalData.time== 1){
this.timer()
console.log('222222222222222222221')
}
},
onUnload:function(){
app.globalData.time = 2;
},
// 点击隐藏弹出蒙版
hiddenMsak() {
var animation = wx.createAnimation({
duration: 500,
timingFunction: "linear",
delay: 0
})
// 点击取消广告
setTimeout(function () {
this.setData({
showAd: true
})
}.bind(this))
},
// 定时器
timer: function () {
var that = this;
setTimeout(function () {
that.getList()
}, 1000);
},
})