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

r3i60tvu  于 2023-11-18  发布在  iOS
关注(0)|答案(1)|浏览(177)

我正在使用axios调用我的API,它会返回如下所示的响应:

  1. {
  2. "name": "test-name",
  3. "attributes": {
  4. "innerAttributes": {
  5. "fundamentals": {
  6. "base": [
  7. "sample-base-1",
  8. "sample-base-2"
  9. ],
  10. "ref": [
  11. "sample-ref-1",
  12. "sample-ref-2"
  13. ]
  14. }
  15. }
  16. }
  17. }

字符串
从API调用中获取响应后,当我使用以下语句将响应记录到控制台时:

  1. console.info("from API", response.data);


其中响应定义为:

  1. const response = await this.axiosInstance.get("my-ledger-endpoint/ledger-XXXXX");


我得到以下登录到我的控制台:

  1. {
  2. "name": "test-name",
  3. "attributes": {
  4. "innerAttributes": {
  5. "fundamentals": {
  6. "base": ["sample-base-1"],
  7. "ref": ["sample-ref-1"]
  8. }
  9. }
  10. }
  11. }


可以看出,innerAttributes键中的fundamental对象在其各自的数组值中只有一个值,即base和ref值。然而,响应(这是正确的)显示baseref属性的两个值。为什么记录的响应缺少值?

qybjjes1

qybjjes11#

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

相关问题