【发布时间】:2020-07-15 08:06:12
【问题描述】:
我需要进行一堆 API 调用并最终像这样组合它们的数据
axios.all([
axios.get('https://api.github.com/users/mapbox'),
axios.get('https://api.github.com/users/phantomjs')
])
.then(responseArr => {
//this will be executed only when all requests are complete
console.log('Date created: ', responseArr[0].data.created_at);
console.log('Date created: ', responseArr[1].data.created_at);
});
但我也想在另一个 API 调用中使用在一个 API 中接收到的数据。有点像
data = axios.get('https://api.github.com/users/mapbox'),
axios.get('https://api.github.com/users/'+data.user);
如何将它用于 5 个 API 调用?
【问题讨论】:
-
使用
await或嵌套.then()对调用进行排序,如图here。