举个栗子
//获取应用实例
//const app = getApp()
//const util = require(‘../../utils/util.js‘)
//const sign = util.sign
//var Md5 = require(‘../../utils/md5.js‘);
Page({
data: {
},
onLoad: function () {
//注释:promise 要用then接收 ,或者await async //参考链接:http://www.imooc.com/wenda/detail/396447
let that = this
that.login().then(res => {
console.log(res) //打印出 1111 或者 2222
})
},
//函数请求
bigBear() { //参考链接:http://www.imooc.com/wenda/detail/535878
return new Promise(function (resolve, reject) {
wx.request({
url: app.globalData.url + ‘/user/wx/login‘,
data: {
openId: wx.getStorageSync("openId")
},
method: "POST",
header: sign(),//根据自己需求
success(res) {
console.log(res)
if(res.code == 500){
resolve(1111)
}else{
resolve(2222)
}
}
})
})
},
})