xr-ajax

用于 HTTP 请求

Usage no npm install needed!

<script type="module">
  import xrAjax from 'https://cdn.skypack.dev/xr-ajax';
</script>

README

基于 Axios 简单封装的 web 端 http 请求库。

✨ 特点

  • 默认超时时间 45 s
  • 200 ~ 500 状态码全部解析
  • withCredentials 默认为 true
  • 支持取消所有请求
  • 支持通过 post 方式发送简单的 formdata

📦 安装

npm i xr-ajax

🔨 使用

import XrAjax from 'xr-ajax';

const ajax = new XrAjax(/* AxiosRequestConfig 传入新的配置会覆盖原有配置 */);
ajax.http.interceptors.request.use(/* 请求拦截器 */);
ajax.http.interceptors.response.use(/* 响应拦截器 */);

ajax
  .get('/user')
  .then(res => {
    /**/
  })
  .catch(err => {
    /**/
  });

TODO

  • 上传文件 upload
  • 防抖
  • 支持依赖注入
  • 支持Observe