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); })
添加回答
举报
0/150
提交
取消