reactjs - 嵌套异步 axios 调用只返回一个对象
问题描述
已经坚持这个一个多小时了,所以有人能指出我正确的方向吗?
在下面的代码片段中,我只取回一个对象而不是多个对象。
我用我的代码片段之间的注释非常详细地解释了这个问题,所以问题应该很清楚。
useEffect(() => {
axios.get('url-here').then((res) => {
res.data.favProperties?.map((el) => {
console.log(el) // this returns id's of saved/liked items
axios.get('url-here').then(async (r) => {
if (r.data) {
console.log(r.data) // Problem starts here
// This returns the full object of the liked items
// But only one object is returned, not every object for which an id was stored
await storageRef
.child(r.data.firebaseRef + '/' + r.data.images[0])
.getDownloadURL()
.then((url) => {
// Here i need to fetch the image for each object
console.log(url)
})
.catch((err) => console.log(err))
}
})
})
})
}, [])
感谢您调查它!亲切的问候
解决方案
推荐阅读
- node.js - express.js 中的参数?
- apache-spark - Spark - X ms 后执行器心跳超时
- javascript - D3:如何使用新数据更新分组栏
- uwp - 如何为 UWP 应用程序使用 OpenSSL dll
- javascript - 操作系统如何将事件与 dom 对象联系起来?
- fonts - 由于某些原因,我的一位用户看到所有数字都被星号“*”替换,这是为什么呢?
- python - 在 PyCharm 中找不到 TensorFlow 模块
- python-2.7 - Python npyscreen:如何从按钮按下启动表单?
- jquery - 点击链接后关闭手机版菜单
- asp.net - Web api 操作过滤器中设置的 CallContext 值不会流向控制器操作