axios记录的响应缺少API请求的值

r3i60tvu  于 11个月前  发布在  iOS
关注(0)|答案(1)|浏览(125)

我正在使用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值。然而,响应(这是正确的)显示baseref属性的两个值。为什么记录的响应缺少值?

qybjjes1

qybjjes11#

这个问题已经解决了。实际上,它既不是axios上的错误,也不是console.info上的错误。当服务调用的响应在调用该服务调用的项目的任何地方发生变化时,就会发生这种情况。在我的情况下,是index.js文件中响应数组上的.splice()方法改变了对响应的原始数组引用。因此,它受到了影响。
希望它能帮助任何面临类似问题的人。

相关问题