1.在login.js文件中加上async和await,因为getWXContext( ) 方法是异步的
exports.main = async (event, context) => { //加上async
console.log(event)
console.log(context)
const wxContext =await cloud.getWXContext() //加上await
return {
event,
openid: wxContext.OPENID,
appid: wxContext.APPID,
unionid: wxContext.UNIONID,
}
}
getOpenid(){
wx.cloud.callFunction({
name: 'login'
}).then((res) => {
const openid = res.result.openid //res.result.openid是小写
// console.log(openid);
this.globalData.openid = openid
if (wx.getStorageSync(openid) == '') {
wx.setStorageSync(openid, [])
}
})
}