解决了 onLoad: async function (options) { await this.getOpenid(); this.getData(); }, async getOpenid(){ let that = this; await wx.cloud.callFunction({ name:'getopenid', }).then(res=>{ that.setData({ id:res.result.openid }) }) console.log(that.data.id) },
使用云函数获取用户openid,在callFunction里面设置setData失败?getOpenid(){ let that = this; wx.cloud.callFunction({ name:'getopenid', complete:res=>{ console.log('云函数获取到的openid:',res.result.openid) var openid = res.result.openid; this.setData({ id:openid }) console.log(that.data.id) #打印出正确的openid } }) console.log(that.data.id) #打印的还是openid修改之前的 }, [图片][图片] 调用getOpenid之后 14,15行输出Page下data的值,14行点开id里面有值,15行取打印不出来?? callFunction函数是有什么恢复现场的操作吗? 我要怎么获取用户的openid呢
2022-01-09