Leanote's Blog
I love Leanote!
Toggle navigation
Leanote's Blog
Home
Chrome
Git
Linux
Windows
Others
工具大全
VsCode
Expo
Html
JavaScript
Npm
Node
Mock
React-Native
React
TypeScript
小程序
插件
正则
Dva
Ant-Design-React
Umi
Vue
Vux
Ant-Design-Vue
Http
Java
flutter
开发小工具
About Me
Archives
Tags
Promise循环依次执行ajax
2021-07-27 09:10:55
4
0
0
admin
``` var arr = [1, 2, 3, 4, 5, 6, 7, 8, 9] function promiseForEach(arr, cb) { let realResult = [] let result = Promise.resolve() arr.forEach((a, index) => { result = result.then(() => { try { return cb(a).then((res) => { realResult.push(res) }) } catch (e) { } }) }) return result.then(() => { return realResult }) } promiseForEach(arr, (ele) => { return new Promise((resolve, reject) => { setTimeout(() => { console.log(ele) return resolve(ele) }, Math.random() * 1000) }) }).then((data) => { console.log("成功") console.log(data) }).catch((err) => { console.log("失败") console.log(err) }) ```
Pre:
vue-router使用笔记
Next:
vue刷新当前路由
0
likes
4
Weibo
Wechat
Tencent Weibo
QQ Zone
RenRen
Submit
Sign in
to leave a comment.
No Leanote account?
Sign up now.
0
comments
More...
Table of content
No Leanote account? Sign up now.