笔记

115 阅读1分钟

数组遍历循环调用接口 用Promise拿到全部数据

const arr = userIdList.map((res, index) => { return this.http.staffList({ userId: +res }).then(item => { return Promise.resolve(item.data.records[0]) }) }) Promise.all([...arr]).then((result) => { console.log(result,'+++') 拿到请求的数据 let list = result.map(item => { return{ deptId: item.deptId, name: item.realName, userId: item.userId, } }) this.cache.set('userId',list) uni.navigateTo({ url:"../taskAdd/taskAdd" }) }).catch((error) => { console.log(error) })