我有这个api urlxxx.com/services/videos/xx/yy
xx = category param
yy = pagination param
我想要查询这个类别和分页参数,例如-
- xxx. com/services/videos/1/0
- xxx. com/services/videos/2/0
- xxx. com/services/videos/125/6
你可以使用Promise.all。创建一个数组(比如url) &——
let urls = [
'xxx. com/services/videos/1/0 ',
'xxx. com/services/videos/2/0',
'xxx. com/services/videos/125/6'
];
// map every url to the promise of the fetch
let requests = urls.map(url => fetch(url));
// Promise.all waits until all jobs are resolved
Promise.all(requests)
.then(responses => responses.forEach(
// process response here
));
或与await
const texts = await Promise.all(urls.map(async url => {
const resp = await fetch(url);
return resp.text(); // or resp.json();
}));