/**获取新消息 */
getNewMessage: function () {
var yinli = this
setInterval(function () {
var key = ‘message’ + yinli.data.chatID
var msgData = wx.getStorageSync(key)
//console.log(msgData)
if (msgData) {
for (let i in msgData) {
yinli.sendMsg(msgData[i])
}
wx.removeStorageSync(key)
}
}, 2000) //循环时间
},
/**消息加入内存中**/
sendMsg: function (sData) {
var that = this
var scrData = that.data.scr
that.data.msg = that.data.msg.concat(sData) //执行到这步,值已经改变
that.setData({ //setData会间歇性不执行
msg: that.data.msg ,
scr: scrData + 100
})
},
部分代码如上,程序流程是定时从本地缓存拿到值后遍历加入变量中,加入变量的操作通过setData实现,问题出在that.setData那里,发现它会间歇性不执行setData,导致内容丢失,希望大家帮我看看哪里出问题了,万分感谢!