1.0.1 • Published 10 months ago

clear-ajax v1.0.1

Weekly downloads
-
License
-
Repository
github
Last release
10 months ago

介绍

前端发送 ajax 请求的工具

使用

在传统项目中使用

<script src="https://gitee.com/xlou/clear-ajax/raw/master/dist/clear-ajax.min.js"></script>
<!-- 建议下载下来使用 -->
<script>
  /* 引入了该 js 文件后,会在 window 上赋值 ajax 对象 */
  ajax({
    url:"https://www.xxx.com",
    params:{
      id:1
    }
  })
  .then(res=>{})
</script>

在 Vue 、React 和 Angular 等 node 项目中使用

安装

npm i clear-ajax -S

main.js / main.ts 中使用

import {ajax} from 'clear-ajax'

ajax({
  url:"https://www.xxx.com",
  params:{
    id:1
  }
})

API

arguments:

参数名是否必选默认值类型解释
method"get"string请求类型,值不区分大小写
headers系统默认object请求头参数
urlstring请求地址
paramsobject会转换为地址栏参数(query string)
dataobjectbody 体参数
uploadProgress(e:object)=>any监听上传文件的进度
downloadProgress(e:object)=>any监听下载文件的进度
getResponse(e:object)=>any获取返回头参数
withCredentialsfalseboolean获取返回头参数
responseType"json"string指定返回数据的类型
timeout60number设置响应超时时间