App({ onLaunch: function () { var logs = wx.getStorageSync('logs') || [] logs.unshift(Date.now()) wx.setStorageSync('logs', logs) var that = this this.getOpenid().then(()=>{ return that.setAdmin() //為什么這里沒有任何console啊,沒有執(zhí)行 }) }, getOpenid: function () { var that = this return new Promise(function (resolve, reject) { console.log(resolve) wx.getStorage({ key: 'openid', success: function (res) { that.globalData.openId = res.data console.log(that.globalData.openId) }, fail: function () { wx.login({ success: res => { var code = res.code; //返回code var appId = ''; var secret = ''; wx.request({ url: 'https://api.weixin.qq.com/sns/jscode2session?appid=' + appId + '&secret=' + secret + '&js_code=' + code + '&grant_type=authorization_code', data: {}, header: { 'content-type': 'json' }, success: function (res) { wx.setStorage({ key: "openid", data: res.data.openid }) that.globalData.openId = res.data.openid } }) } }) } }) }) },目的是要先 設(shè)置openid到data后,再傳給服務(wù)器驗(yàn)證,但是wxrequst異步要promise來規(guī)定執(zhí)行順序啊,但是這里為什么then后不執(zhí)行呢,求大大解答
小程序 Promise執(zhí)行問題
暮色呼如
2019-03-30 15:19:15