1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
| const urls = [ 'https://api.example.com/data1', 'https://api.example.com/data2', 'https://api.example.com/data3' ];
const promises = urls.map(url => fetch(url).then(response => response.json()));
Promise.all(promises) .then(results => { console.log('全部请求成功:', results); }) .catch(error => { console.error('有请求失败:', error); });
|