小程序云函数,为啥这个外部获取不到数据?
App({
globalData: {
userInfo: null,
openid:null
},
onLaunch() {
wx.cloud.init({
env:'hope-7g8c1n2f6997c60e' //初始化
})
//获取用户openid
wx.cloud.callFunction({
name:"comlogin",
success:res => {
this.globalData.openid = res.result.openid
//数据库查找
wx.cloud.database().collection('user').where({
_openid:res.result.openid
}).get().then(result =>{
console.log("1.内部未赋值前:", this.globalData.userInfo)
this.globalData.userInfo = result.data[0]
console.log("2.内部赋值后:", this.globalData.userInfo)
})
console.log("3.数据库查询外部", this.globalData.userInfo)
}
})
console.log("4.callFunction外部",this.globalData.userInfo)
}
})