上一页 1 ··· 12 13 14 15 16 17 18 19 20 ··· 45 下一页
摘要: 使用 multipart/form-data 类型发起 POST 请求 使用 FormData API 浏览器 const form = new FormData(); form.append('my_field', 'my value'); form.append('my_buffer', new 阅读全文
posted @ 2023-11-22 15:12 厚礼蝎 阅读(222) 评论(0) 推荐(0)
摘要: 默认情况下,axios将 JavaScript 对象序列化为 JSON 。 要以 application/x-www-form-urlencoded 格式发送数据,您可以使用以下选项之一。 浏览器 在浏览器中,可以使用 URLSearchParams API,如下所示: const params = 阅读全文
posted @ 2023-11-22 15:00 厚礼蝎 阅读(91) 评论(0) 推荐(0)
摘要: AbortController 从 v0.22.0 开始,Axios 支持以 fetch API 方式—— AbortController 取消请求: const controller = new AbortController(); axios.get('/foo/bar', { signal: 阅读全文
posted @ 2023-11-22 14:33 厚礼蝎 阅读(219) 评论(0) 推荐(0)
摘要: axios.get('/user/12345') .catch(function (error) { if (error.response) { // 请求成功发出且服务器也响应了状态码,但状态代码超出了 2xx 的范围 console.log(error.response.data); conso 阅读全文
posted @ 2023-11-22 14:15 厚礼蝎 阅读(94) 评论(0) 推荐(0)
摘要: 在请求或响应被 then 或 catch 处理前拦截它们。 // 添加请求拦截器 axios.interceptors.request.use(function (config) { // 在发送请求之前做些什么 return config; }, function (error) { // 对请求 阅读全文
posted @ 2023-11-22 14:10 厚礼蝎 阅读(39) 评论(0) 推荐(0)
摘要: 你可以指定将被用在各个请求的配置默认值 全局 axios 默认值 axios.defaults.baseURL = 'https://api.example.com'; axios.defaults.headers.common['Authorization'] = AUTH_TOKEN; axio 阅读全文
posted @ 2023-11-21 00:15 厚礼蝎 阅读(85) 评论(0) 推荐(0)
摘要: 一个请求的响应包含以下信息。 { // `data` 由服务器提供的响应 data: {}, // `status` 来自服务器响应的 HTTP 状态码 status: 200, // `statusText` 来自服务器响应的 HTTP 状态信息 statusText: 'OK', // `hea 阅读全文
posted @ 2023-11-21 00:08 厚礼蝎 阅读(60) 评论(0) 推荐(0)
摘要: 这些是创建请求时可以用的配置选项。 只有 url 是必需的。如果没有指定 method,请求将默认使用 GET 方法。 { // `url` 是用于请求的服务器 URL url: '/user', // `method` 是创建请求时使用的方法 method: 'get', // 默认值 // `b 阅读全文
posted @ 2023-11-21 00:04 厚礼蝎 阅读(82) 评论(0) 推荐(0)
摘要: 创建一个实例 可以使用自定义配置新建一个 axios 实例 axios.create([config]) const instance = axios.create({ baseURL: 'https://some-domain.com/api/', timeout: 1000, headers: 阅读全文
posted @ 2023-11-20 23:57 厚礼蝎 阅读(71) 评论(0) 推荐(0)
摘要: 可以通过向 axios 传递相关配置来创建请求 axios(config) // 发送 POST 请求 axios({ method: 'post', url: '/user/12345', data: { firstName: 'Fred', lastName: 'Flintstone' } }) 阅读全文
posted @ 2023-11-20 23:52 厚礼蝎 阅读(39) 评论(0) 推荐(0)
上一页 1 ··· 12 13 14 15 16 17 18 19 20 ··· 45 下一页