文章詳情頁
javascript - 怎么用fetch+async模擬jQuery.when
瀏覽:119日期:2023-09-30 14:21:03
問題描述
單個fetch+async
(async() => { try { var response = await fetch(url); var data = await response.json(); console.log(data); } catch (e) { console.log('Booo') }})();
如何像$.when一樣發(fā)起多個請求
$.when(...reqArr).done(function (...data) { }
類似
requestByFetch(urls)
問題解答
回答1:使用Promise.all
回答2:方法就是 Promise.all() , 實(shí)現(xiàn)如下.
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
標(biāo)簽:
JavaScript
上一條:javascript - nodejs在一個頁面下顯示mongodb數(shù)據(jù)庫里的內(nèi)容,頁面出現(xiàn)is not defined錯誤,是哪里出了問題?下一條:javascript - 為什么用mocha測試的時候提示說nodejs版本過低
相關(guān)文章:
1. 注冊賬戶文字不能左右分離2. JavaScript事件3. html5 - ElementUI table中el-table-column怎么設(shè)置百分比顯示。4. javascript - table列過多,有什么插件可以提供列排序和選擇顯示列的功能5. python - 使用readlines()方法讀取文件內(nèi)容后,再用for循環(huán)遍歷文件與變量匹配時出現(xiàn)疑難?6. javascript - ES6標(biāo)準(zhǔn)入門中l(wèi)et命令提到的for循環(huán)打印i是10,如果不用let怎么替換?7. showpassword里的this 是什么意思?代表哪個元素8. 對mysql某個字段監(jiān)控的功能9. python - 為什么正常輸出中文沒有亂碼,zip函數(shù)之后出現(xiàn)中文編程unicode編碼的問題,我是遍歷輸出的啊。10. html - vue項(xiàng)目中用到了elementUI問題
排行榜

熱門標(biāo)簽