当前第2页 返回上一页
通过promise.all()方法把promise包装成一个新的promise实例
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 | getInfo(item ,index) {
const ms = 1000 * Math.ceil(Math.random() * 3)
return new Promise((resolve,reject) => {
setTimeout(() => {
axios.get(id).then((result) => {
resolve(result)
})
}, ms)
})
}
let promise = arr.map((item,index) = > {
arr.forEach((item, index) => {
return getInfo(item, index)
})
})
Peomise.all(promise).then((allData) => {
arr.forEach((item, index) => {
})
})
|
本文来自 js教程 栏目,欢迎学习!
以上就是解决for循环中异步请求顺序不一致的问题的详细内容,更多文章请关注木庄网络博客!
返回前面的内容
相关阅读 >>
详解es6中的for … of循环和可迭代对象
javascript中for in语句怎么用
浅谈input中的name,value以及label中的for
解决for循环中异步请求顺序不一致的问题
更多相关阅读请进入《for》频道 >>
人民邮电出版社
本书对 Vue.js 3 技术细节的分析非常可靠,对于需要深入理解 Vue.js 3 的用户会有很大的帮助。——尤雨溪,Vue.js作者
转载请注明出处:木庄网络博客 » 解决for循环中异步请求顺序不一致的问题