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

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

待兩個接口都返回再操作的情況,怎么處理,有哪些解決方法

待兩個接口都返回再操作的情況,怎么處理,有哪些解決方法

慕容森 2018-08-18 21:03:21
fetch('http://10.3.134.173/jsonp-test/data/dish_getbypage.php?start=1',     ).then((response)=>         response.json()     ).then((res)=>{        console.log(res[0].name);     }); fetch('http://10.3.134.173/jsonp-test/data/dish_getbypage.php?start=2',     ).then((response)=>         response.json()     ).then((res)=>{        console.log(res[0].name);     })同時發起請求,比如一個等待一秒,一個等待兩秒返回,然后待都返回結果然后執行后續操作,具體該怎么操作,用promise.all怎么寫
查看完整描述

2 回答

?
揚帆大魚

TA貢獻1799條經驗 獲得超9個贊

let p1 = new Promise((resolve, reject) => {    // 第一個接口請求
    fetch('....').then((res) => {
        resolve(res);
    })
})let p2 = new Promise((resolve, reject) => {    // 第二個接口請求
    fetch('....').then((res) => {
        resolve(res);
    })
})Promise.all([p1,p2]).then(data => {    console.log(data);
})


查看完整回答
反對 回復 2018-08-19
  • 2 回答
  • 0 關注
  • 924 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

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

幫助反饋 APP下載

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

公眾號

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