Maison > Questions et réponses > le corps du texte
单个fetch+async
(async() => {
try {
var response = await fetch(url);
var data = await response.json();
console.log(data);
} catch (e) {
console.log("Booo")
}
})();
如何像$.when一样发起多个请求
$.when(...reqArr).done(function (...data) {
}
类似
requestByFetch(urls)
迷茫2017-04-17 16:31:43
方法就是 Promise.all() , 实现如下.
let all = async (urls) => {
let get = async(url) => {
let res = await fetch(url);
...
return res;
}
let promises = urls.map(async (url) => await get(url));
let data = await Promise.all(promises);
return data;
}
soonfy