亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

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

關于微信小程序中異步登錄的問題? 文件執行順序的問題 與promise問題

關于微信小程序中異步登錄的問題? 文件執行順序的問題 與promise問題

Helenr 2019-05-21 17:19:24
目前我將登錄操作寫在了app.js中,獲取到微信的code后,向自己的服務器獲取驗證access-token.代碼如下app.jsonLaunch:function(){wx.login({success:res=>{//發送res.code到后臺換取openId,sessionKey,unionIdconfig.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;}elseif(res.data.status==false){console.log(res.data.data);}else{}}})},在另一個文件met.js中需要通過獲取的uidaccessToken來請求獲取數據.代碼如下met.jseggGetRemoteWords:function(){varself=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,})vartotal=self.data.word.wordArray.length;self.setData({"word.wordInfo.total":total});}elseif(res.data.status==false){}else{}}})},但是目前總是met.js中的函數eggGetRemoteWords總早于app.js中initUserInfo登錄函數執行,導致無法獲取到數據因為js異步的原因.請問大家這應該怎么處理呢?我了解到promise請問如果目前的需求將如何實現呢?
查看完整描述

2 回答

  • 2 回答
  • 0 關注
  • 603 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號