如何从 VueJS 中的 http 响应中获取 headers?
How to get headers from http response in VueJS?
我使用 axios 从后端检索一些数据。我发送一个请求,我有一个回应。我想读一些我的 headers。我尝试了很多东西,但没有人在工作。
我的 headers 包含以下 headers 'content-type', content-length', 'x-wp-total', 'x-wp-totalpages'
.
我尝试使用 response.headers('content-type')
获取 headers,但出现错误 response.headers is not function。我有麻烦了。
我的问题好像很简单。从响应中获取 headers 的语法是什么?
你看过https://github.com/axios/axios#response-schema了吗?
// `headers` the HTTP headers that the server responded with
// All header names are lower cased and can be accessed using the bracket notation.
// Example: `response.headers['content-type']`
headers: {},
相关:
根据您的日志,应该是 response.headers["content-type"]
。或者你也可以调用 response.headers.contentType
通常也可以。
headers是response的属性。它是一个 object 非函数,因此您不能像 "headers()" 那样将其用作函数。如果你想访问 headers 的属性,你应该使用 '.'或 []
我使用 axios 从后端检索一些数据。我发送一个请求,我有一个回应。我想读一些我的 headers。我尝试了很多东西,但没有人在工作。
我的 headers 包含以下 headers 'content-type', content-length', 'x-wp-total', 'x-wp-totalpages'
.
我尝试使用 response.headers('content-type')
获取 headers,但出现错误 response.headers is not function。我有麻烦了。
我的问题好像很简单。从响应中获取 headers 的语法是什么?
你看过https://github.com/axios/axios#response-schema了吗?
// `headers` the HTTP headers that the server responded with
// All header names are lower cased and can be accessed using the bracket notation.
// Example: `response.headers['content-type']`
headers: {},
相关:
根据您的日志,应该是 response.headers["content-type"]
。或者你也可以调用 response.headers.contentType
通常也可以。
headers是response的属性。它是一个 object 非函数,因此您不能像 "headers()" 那样将其用作函数。如果你想访问 headers 的属性,你应该使用 '.'或 []