AI助手支持GPT4.0
使用云函数获取用户openid,在callFunction里面设置setData失败?Use cloud function to get the user's openid, and set the setData in the callFunction failed?
使用云函数获取用户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呢
Getopenid() {let that = this; Wx. Cloud. Callfunction ({Name: 'getopenid', complete: result = > {console. Log ('openid obtained by cloud function: ', result. Result. Openid) var openid = result. Result. Openid; this. SetData ({ID: openid}) console Log (that. Data. ID) # print out the correct openid}}) console Log (that. Data. ID) # prints the} before openid is modified. After calling getopenid, lines 14 and 15 output the value of data under the page. In line 14, click Open ID, there is a value in it, and line 15 can't print it?? Is there any operation to restore the scene in the callfunction function? How do I get the user's openid
解决了
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) },