【发布时间】:2020-02-19 05:26:03
【问题描述】:
正如axios GitHub页面所说,axios请求的默认响应是:
{
// `data` is the response that was provided by the server
data: {},
// `status` is the HTTP status code from the server response
status: 200,
// `statusText` is the HTTP status message from the server response
statusText: 'OK',
// `headers` the headers that the server responded with
// All header names are lower cased
headers: {},
// `config` is the config that was provided to `axios` for the request
config: {},
// `request` is the request that generated this response
// It is the last ClientRequest instance in node.js (in redirects)
// and an XMLHttpRequest instance in the browser
request: {}
}
问题:
我的 API 响应架构是:
{
success: true,
message: '',
data: {}
}
所以每次我提出请求时,我都必须像这样处理响应:
(...).then((res) => res.data.data);
如何更改 axios 的响应模式以避免每次都执行.data.data?
【问题讨论】:
标签: vue.js xmlhttprequest axios