小程序定时刷新问题
坑: 在使用mqtt通信时,定时刷新不能放在onShow()里面 ,否则会导致页面死循环(在各个页面不停的跳转)
intervalRefresh: function (){
var _this = this
var timer = setInterval(function () {
app.util.reqAsync('接口', {
presaleId: _this.data.orderId,
businessId: _this.data.businessId
}).then((res) => {
if (res.data.code == 1) {
// console.log(res,'-----res1')
if (res.data.data != []) {
_this.setData({
orderStatus: res.data.data[0].orderStatus,
payStatus: res.data.data[0].payStatus
})
if (res.data.data[0].orderStatus == 4) {
_this.sendMsg()
}
}
}
})
}, 10000)
_this.setData({
timer
})
},
调用:
onLoad: function (options) {
this.intervalRefresh()
}
清除interval 则在mqtt 的接收消息中 clearInterval()
以上。。。