For chestnut
// Get application examples
//const app = getApp()
// const util = require ( '../../ utils / util.js')
//const sign = util.sign
//var Md5 = require('../../utils/md5.js');
Page({
data: {
},
the onLoad: function () {
// NOTE: promise then use the received, or await async // reference links: http://www.imooc.com/wenda/detail/396447
let that = this
that.login().then(res => {
console.log (res) // 1111 or 2222 to print out
})
},
// function requests
bigBear () {// reference links: http://www.imooc.com/wenda/detail/535878
return new new Promise (function (Resolve, Reject) {
wx.request({
url: app.globalData.url + '/user/wx/login',
data: {
openId: wx.getStorageSync("openId")
},
method: "POST",
header: sign (), // according to their needs
success(res) {
console.log(res)
if(res.code == 500){
resolve(1111)
}else{
resolve(2222)
}
}
})
})
},
})