第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號安全,請及時綁定郵箱和手機(jī)立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

關(guān)于微信小程序中異步登錄的問題? 文件執(zhí)行順序的問題 與promise問題

關(guān)于微信小程序中異步登錄的問題? 文件執(zhí)行順序的問題 與promise問題

幕布斯6054654 2019-03-20 18:19:55
目前我將登錄操作寫在了 app.js 中, 獲取到微信的 code 后,向自己的服務(wù)器獲取驗證 access-token .代碼如下app.js    onLaunch: function () {        wx.login({            success: res => {                // 發(fā)送 res.code 到后臺換取 openId, sessionKey, unionId                config.code = res.code;                this.initUserInfo();            }        })    },            // 初始化用戶信息    initUserInfo: function () {        wx.request({            url: config.baseUrl + "/index.php?m=Api&c=User&a=initUserInfo",            method: 'POST',            header: {                "Content-Type": "application/x-www-form-urlencoded"            },            data: {                source_type: 'wxapp',                code: config.code,            },            success: function (res) {                if (res.data.status == true) {                                        config.uid = res.data.data.uid;                    config.accessToken = res.data.data.wxapp_access_token;                          } else if (res.data.status == false) {                    console.log(res.data.data);                } else {                }            }        })    },在另一個文件 met.js 中需要通過獲取的 uid accessToken 來請求獲取數(shù)據(jù).代碼如下met.js    eggGetRemoteWords: function() {        var self = this;        wx.request({            url: app.config.baseUrl + "/index.php?m=Api&c=Learning&a=getLearningWord",            method: 'POST',            header: {                "Content-Type": "application/x-www-form-urlencoded"            },            data: {                uid: app.config.uid,                access_token: app.config.accessToken            },            success: function (res) {                if (res.data.status == true) {                    self.setData({                        'word.wordArray': res.data.data,                    }) 但是目前總是 met.js 中的函數(shù) eggGetRemoteWords 總早于 app.j s中 initUserInfo 登錄函數(shù)執(zhí)行,導(dǎo)致無法獲取到數(shù)據(jù) 因為 js 異步的原因. 請問大家這應(yīng)該怎么處理呢? 我了解到 promise 請問如果目前的需求將如何實現(xiàn)呢?
查看完整描述

4 回答

?
臨摹微笑

TA貢獻(xiàn)1982條經(jīng)驗 獲得超2個贊

用async函數(shù)調(diào)用,initUserInfo和eggGetRemoteWords都封裝成promise


查看完整回答
反對 回復(fù) 2019-04-02
?
largeQ

TA貢獻(xiàn)2039條經(jīng)驗 獲得超8個贊

用promise二次封裝下你的request就行了


查看完整回答
反對 回復(fù) 2019-04-02
  • 4 回答
  • 0 關(guān)注
  • 647 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補(bǔ)貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動學(xué)習(xí)伙伴

公眾號

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號