Axios 是一个基于 Promise 的 HTTP 客户端,用于浏览器和 Node.js。在使用 Axios 发送请求时,你可以通过配置对象来设置请求的一些参数。以下是一些常见的 Axios 请求配置:

1. method: 请求方法,默认为 'get'。
   axios({
     method: 'post',
     // 其他配置...
   });

2. url: 请求的 URL 地址。
   axios({
     url: 'https://example.com/api/data',
     // 其他配置...
   });

3. params: URL 参数,用于 GET 请求。
   axios({
     method: 'get',
     url: 'https://example.com/api/data',
     params: {
       key1: 'value1',
       key2: 'value2',
     },
     // 其他配置...
   });

4. data: 请求体数据,用于 POST 请求。
   axios({
     method: 'post',
     url: 'https://example.com/api/data',
     data: {
       key1: 'value1',
       key2: 'value2',
     },
     // 其他配置...
   });

5. headers: 请求头配置。
   axios({
     headers: {
       'Content-Type': 'application/json',
       // 其他请求头...
     },
     // 其他配置...
   });

6. timeout: 请求超时时间(毫秒)。
   axios({
     timeout: 5000, // 5秒超时
     // 其他配置...
   });

7. withCredentials: 是否携带跨域请求的凭证信息(Cookie)。
   axios({
     withCredentials: true,
     // 其他配置...
   });

8. responseType: 服务器响应的数据类型,可以是 'json'、'text' 等。
   axios({
     responseType: 'json',
     // 其他配置...
   });

这只是一些常见的请求配置,具体可以参考 Axios 官方文档中的 [配置参数](https://axios-http.com/docs/req_config) 部分。在实际使用中,你可以根据需求选择性地配置这些参数。


转载请注明出处:http://www.zyzy.cn/article/detail/6279/Axios