【问题标题】:Can't access X-Total-Count header from json-server无法从 json-server 访问 X-Total-Count 标头
【发布时间】:2021-04-14 20:00:12
【问题描述】:

我正在使用 axios 从 JSON 服务器请求数据。虽然我可以看到 JSON 服务器正在使用 Postman 返回 X-Total-Count 标头,但 axios 没有看到该标头。我使用的是 http 协议,所以 CORS 应该不是问题。我错过了什么?

这是对 json-server 的调用:

const resp = await axios.get('/orders?_start=0&_end=100');
const orderCount = resp.headers['X-Total-Count'];

以下是收到的标头(在 Chrome Devtools 中捕获)。请注意,X-Total-Count 缺失:

Postman 中的相同 HTTP 调用显示返回了 X-Total-Count

【问题讨论】:

    标签: axios json-server


    【解决方案1】:

    解决了。我使用了命令行选项--no-cors,然后 axios 开始看到 X-Total-Count 标头。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2019-02-23
      • 1970-01-01
      • 2020-07-02
      • 2021-09-24
      • 2022-12-22
      • 2023-03-21
      • 2021-07-04
      • 2021-08-20
      相关资源
      最近更新 更多