1. <ul id="0c1fb"></ul>

      <noscript id="0c1fb"><video id="0c1fb"></video></noscript>
      <noscript id="0c1fb"><listing id="0c1fb"><thead id="0c1fb"></thead></listing></noscript>

      99热在线精品一区二区三区_国产伦精品一区二区三区女破破_亚洲一区二区三区无码_精品国产欧美日韩另类一区

      RELATEED CONSULTING
      相關(guān)咨詢
      選擇下列產(chǎn)品馬上在線溝通
      服務(wù)時(shí)間:8:30-17:00
      你可能遇到了下面的問(wèn)題
      關(guān)閉右側(cè)工具欄

      新聞中心

      這里有您想知道的互聯(lián)網(wǎng)營(yíng)銷解決方案
      vue項(xiàng)目中利用promise解決并發(fā)請(qǐng)求的方法-創(chuàng)新互聯(lián)

      這篇文章將為大家詳細(xì)講解有關(guān)vue項(xiàng)目中利用promise解決并發(fā)請(qǐng)求的方法,文章內(nèi)容質(zhì)量較高,因此小編分享給大家做個(gè)參考,希望大家閱讀完這篇文章后對(duì)相關(guān)知識(shí)有一定的了解。

      作為一家“創(chuàng)意+整合+營(yíng)銷”的成都網(wǎng)站建設(shè)機(jī)構(gòu),我們?cè)跇I(yè)內(nèi)良好的客戶口碑。成都創(chuàng)新互聯(lián)提供從前期的網(wǎng)站品牌分析策劃、網(wǎng)站設(shè)計(jì)、成都做網(wǎng)站、網(wǎng)站制作、創(chuàng)意表現(xiàn)、網(wǎng)頁(yè)制作、系統(tǒng)開(kāi)發(fā)以及后續(xù)網(wǎng)站營(yíng)銷運(yùn)營(yíng)等一系列服務(wù),幫助企業(yè)打造創(chuàng)新的互聯(lián)網(wǎng)品牌經(jīng)營(yíng)模式與有效的網(wǎng)絡(luò)營(yíng)銷方法,創(chuàng)造更大的價(jià)值。

      場(chǎng)景需求:

      需要同時(shí)請(qǐng)求5個(gè)接口

      都請(qǐng)求成功后執(zhí)行下一步操作

      解決方法:

      定義一個(gè)變量i=5,請(qǐng)求成功一個(gè)接口,讓i–,直到i=0時(shí)執(zhí)行下一個(gè)操作,否則不執(zhí)行

      axios.all 并發(fā)請(qǐng)求,.then(axios.spread(function(callback1, callback2)){})

      promise.all 并發(fā)請(qǐng)求,.then(function([callback1, callback2]){})

      1、回調(diào)地獄:

      函數(shù)作為參數(shù)層層嵌套

      代替的為.then的鏈?zhǔn)讲僮?/p>

      2、promise.all并發(fā)請(qǐng)求

      引入接口

      import {getSellerDetail} from '../../api/seller'

      import {getMemberCardInfo} from '../../api/pay_online/index'

      數(shù)據(jù)處理

      1. 創(chuàng)建一個(gè)Promise實(shí)例,獲取數(shù)據(jù)

      2. 并把數(shù)據(jù)傳遞給處理函數(shù)resolve和reject

      3. promise在聲明時(shí)就執(zhí)行了

      created(){
        if (this.$route.query.type){
          this.type = this.$route.query.type;
          this.sellerId = this.$route.query.targetId;
          this.initApi()
        }
      },
      methods: {
        initApi(){
          `// 商戶信息`
          let SellerDetailApi = new Promise((resolve, reject) => {
            getSellerDetail(this.sellerId).then( res => {
              resolve(res)  // resolve(res.data)
            }).catch( err => {
              reject(res)
            })
          })
          `// 會(huì)員卡信息`
          let MemberCardInfoApi = new Promise((resolve, reject) => {
            getMemberCardInfo(this.sellerId, this.payMoney).then( res => {
              resolve(res) // resolve(res.data)
            }).catch( err => {
              reject(res)
            })
          })
          `// Promise的all方法,等數(shù)組中的所有promise對(duì)象都完成執(zhí)行`
          Promise.all([SellerDetailApi, MemberCardInfoApi]).then( res => {
            this.loading = false;
            // 商戶信息
            this.detail = res[0].data.detail;
            this.sellerPic = this.detail.picture;
            this.sellerName = this.detail.name;
            this.discount = this.detail.discount;
            // 會(huì)員卡信息
            this.cardDetail = res[1].data;
            this.balance = this.cardDetail.balance; //余額
            this.rechargeTip = this.cardDetail.rechargeTip; // 付款金額提示充值
          }).catch( err => {
            console.log(err)
          })
        }
      }

      文章題目:vue項(xiàng)目中利用promise解決并發(fā)請(qǐng)求的方法-創(chuàng)新互聯(lián)
      鏈接地址:http://www.ef60e0e.cn/article/djcoej.html
      99热在线精品一区二区三区_国产伦精品一区二区三区女破破_亚洲一区二区三区无码_精品国产欧美日韩另类一区
      1. <ul id="0c1fb"></ul>

        <noscript id="0c1fb"><video id="0c1fb"></video></noscript>
        <noscript id="0c1fb"><listing id="0c1fb"><thead id="0c1fb"></thead></listing></noscript>

        谢通门县| 海宁市| 易门县| 阿拉善左旗| 内黄县| 梨树县| 南丰县| 镇康县| 柳江县| 十堰市| 砚山县| 深泽县| 从江县| 仪陇县| 平湖市| 托里县| 萨迦县| 板桥市| 齐齐哈尔市| 思南县| 宜川县| 微山县| 长宁区| 湄潭县| 汝城县| 延津县| 丹棱县| 三门县| 永修县| 布拖县| 永兴县| 苏州市| 黔南| 新巴尔虎右旗| 栾川县| 崇左市| 图们市| 江永县| 宽甸| 柳河县| 正定县|