我正在使用axios调用我的API,它会返回如下所示的响应:
{
"name": "test-name",
"attributes": {
"innerAttributes": {
"fundamentals": {
"base": [
"sample-base-1",
"sample-base-2"
],
"ref": [
"sample-ref-1",
"sample-ref-2"
]
}
}
}
}
字符串
从API调用中获取响应后,当我使用以下语句将响应记录到控制台时:
console.info("from API", response.data);
型
其中响应定义为:
const response = await this.axiosInstance.get("my-ledger-endpoint/ledger-XXXXX");
型
我得到以下登录到我的控制台:
{
"name": "test-name",
"attributes": {
"innerAttributes": {
"fundamentals": {
"base": ["sample-base-1"],
"ref": ["sample-ref-1"]
}
}
}
}
型
可以看出,innerAttributes
键中的fundamental对象在其各自的数组值中只有一个值,即base和ref值。然而,响应(这是正确的)显示base
和ref
属性的两个值。为什么记录的响应缺少值?
1条答案
按热度按时间qybjjes11#
这个问题已经解决了。实际上,它既不是
axios
上的错误,也不是console.info
上的错误。当服务调用的响应在调用该服务调用的项目的任何地方发生变化时,就会发生这种情况。在我的情况下,是index.js
文件中响应数组上的.splice()
方法改变了对响应的原始数组引用。因此,它受到了影响。希望它能帮助任何面临类似问题的人。