无法读取未定义的属性“协议":Axios反应 [英] Cannot read property 'protocol' of undefined : axios react

查看:241
本文介绍了无法读取未定义的属性“协议":Axios反应的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

const config = {
   headers: { "Content-Type": "application/octet-stream" }
}

let files = this.state.files
let promises = []
files.map((item ,index) => {
   promises.push(axios.put(this.props.deal.authURL[index], item, config))
})

我收到此错误:

未捕获(承诺)TypeError:无法读取未定义的属性协议"

Uncaught (in promise) TypeError: Cannot read property 'protocol' of undefined

我的目标是将Axios调用的所有结果存储在promise数组中.然后使用Promise.all()函数一次解决所有问题.无法弄清楚为什么会出现错误.

My aim is to store all the result of the Axios calls inside promises array. And then use Promise.all() function to resolve all at once. Can't figure why the error is there.

任何帮助都将受到赞赏.谢谢

Any sort of help is appreciated. Thanks

推荐答案

this.props.deal.authURL[index]返回未定义的url,这是随机错误的原因.

this.props.deal.authURL[index] was returning an undefined url and that was the reason for the random error.

这篇关于无法读取未定义的属性“协议":Axios反应的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆