业务需要在app.js中获取用户的openid,然后在其他页面作为查询数据库判别条件。
我在app.js onLunch函数中使用如下代码获取openid
this.globalData = {
openid: ''
}
wx.cloud.callFunction({
name:'login',
}).then(res => {
that.globalData.openid = res.result.openid
})
console.log(that.globalData.openid)
但是最后打印显示globalData.openid为空值,请问应该如何解决
异步赋值问题,得写到then里面 wx.cloud.callFunction({ name:'login', }).then(res => { that.globalData.openid = res.result.openid; console.log(that.globalData.openid) })