watcher.close() 关掉后,无法再监听。不知道如何再打开
requestId: "1618705516709_0.3624532906210909"
"watchid_1618705516705_0.3589298669638463"
【代码如下】
imChat_get: function(useropenid){
console.log("开始 imChat_get 方法")
var that = this
const db = wx.cloud.database()
const _ = db.command
db.collection('mailChat')
.where({
_openid: _.eq(app.globalData._openid).or(_.eq(useropenid)),
})
.where({
people: _.eq(useropenid).or(_.eq(app.globalData._openid))
})
.orderBy('createDate', 'asc')
.limit(5)
.watch({
onChange: function(snapshot) {
console.log('----------- snapshot为', snapshot)
console.log('docChanges为', snapshot.docChanges)
console.log("有聊天记录")
that.setData({
mailChatArray_new: snapshot.docChanges //最新消息
})
console.log('docs为', snapshot.docs)
that.setData({
mailChatArray: snapshot.docs //历史消息
})
console.log('is init data', snapshot.type === 'init')
setTimeout(() => {
await watcher.close()
}, 300);
},
onError: function(err) {
console.error('the watch closed because of error', err)
}
})
},