app.js的 globalData怎么在tabber的首页获取不到数据,在其他页面就能获取到?
// app.js
App({
globalData: {
userInfo: null,
visitorNotify: {
visitorExist: false,
visitorNumber: ''
}
},
async checkLogin() {
const db = wx.cloud.database()
const user = await wx.cloud.callFunction({
name: 'loginCheck',
data: {}
})
const re = await db.collection('user').where({
openid: user.result.openid
}).get().then(res => {
this.userInfo = res.data[0]
this.globalData.userInfo = res.data[0];
})
},
async onLaunch() {
wx.cloud.init({
env: 'green-7gnsotdye1b374a3',
traceUser: true
})
await this.checkLogin();
await this.notifyPlus();
},
async notifyPlus() {
const db = wx.cloud.database()
await db.collection('notify').where({
notifyType: 1,
notifyOpenid: this.globalData.userInfo.openid,
}).watch({
onChange: (snapshot) => {
if (snapshot.docChanges.length) {
console.log(snapshot.docChanges);
this.globalData.visitorNotify.visitorExist=true
this.globalData.visitorNotify.visitorNumber=snapshot.docChanges.length
}
},
onError: (err) => {
console.error('the watch closed because of error', err);
}
})
console.log('登录了')
}
})
[图片] 这是tabber页面的首页面, [图片] 这是tabber的其他页面,这个页面可以获取到globalData的数据,首页的tabber就不行,这是为什么?