Small micro-channel cloud development program error to solve: Setting data field "openid" to undefined is invalid.

 

Recent cloud development in small micro-channel learning program, just start having problems.

Click for openid start when the console error:

[Cloud Function] [login] user openid: undefined

VM97:1 Setting data field "openid" to undefined is invalid.

 

Then I started to go to Baidu search to solve this problem, various methods have been tried, still not been resolved. A change of thinking, began tracking codes:

 

Hover to the right of index.js: 55, I found a line 55 reported /pages/index/index.js file errors, we open the page to see:

 

Found printed on the console res.result.openId, this variable is undefined, in order to see the specific reasons, we first look res print things in it,

Behind the increase in one line of code: console.log (res) to see what is printed:

Let us look at the results compiled console print:

 

 

We can see from the results, the acquisition of openId interface call was successful, but the location openId field in userInfo at the result, but before the code is accessed through a result openId field down, so undefined behavior occurs, guess Tencent may be a problem due to the adjustment resulting from the interface. At this point, the truth. We went to the line 55, 56 /pages/index/index.js modify the file, read as follows:

console.log('[云函数] [login] user openid: ', res.result.userInfo.openId)
app.globalData.openid = res.result.userInfo.openId

  

Finally, compile it, successfully resolved the problem!

 

Guess you like

Origin www.cnblogs.com/xindekaishi/p/11313052.html