页面方法内部调用云函数和方法体内的代码执行顺序问题?
/**
* 获取用户信息
* [@param](/user/param) {*} event
*/
onGetUserInfo: function(event){
let that = this
let rawData = JSON.parse(event.detail.rawData)
wx.cloud.callFunction({
name: "login",
success: res => {
that.setData({
openid: res.result.openid,
userinfo: event.detail.userInfo
})
that.data.userinfo.openid = that.data.openid //userinfo 保存openid信息
console.log("data openid: ", that.data.userinfo.openid)
},
fail: res => {
console.log(res.result)
}
})
that.data.userinfo.openid = that.data.openid //userinfo 保存openid信息
that.data.userinfo.headImg = rawData.avatarUrl //userinfo 保存头像地址信息
console.log("data: ", that.data.userinfo.openid)
console.log("data all: ", that.data)
wx.setStorageSync('userinfo', that.data.userinfo)
}
为什么后面的两个console比云函数回调success中的console先执行。