为了账号安全,请及时绑定邮箱和手机立即绑定

待两个接口都返回再操作的情况,怎么处理,有哪些解决方法

待两个接口都返回再操作的情况,怎么处理,有哪些解决方法

慕容森 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 关注
  • 899 浏览
慕课专栏
更多

添加回答

举报

0/150
提交
取消
微信客服

购课补贴
联系客服咨询优惠详情

帮助反馈 APP下载

慕课网APP
您的移动学习伙伴

公众号

扫描二维码
关注慕课网微信公众号