https://github.com/michaeljohnn/com-axios
基于 axios 的请求组件封装,默认某些配置,如 xsrf 开启等
https://github.com/michaeljohnn/com-axios
Last synced: over 1 year ago
JSON representation
基于 axios 的请求组件封装,默认某些配置,如 xsrf 开启等
- Host: GitHub
- URL: https://github.com/michaeljohnn/com-axios
- Owner: michaeljohnn
- Created: 2019-04-02T08:55:40.000Z (about 7 years ago)
- Default Branch: master
- Last Pushed: 2019-04-03T02:55:04.000Z (about 7 years ago)
- Last Synced: 2025-01-11T04:53:12.822Z (over 1 year ago)
- Language: JavaScript
- Size: 99.6 KB
- Stars: 0
- Watchers: 3
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# com-axios
通用请求组件,兼容前端和node端请求
## 使用示例
```
import comAxios from 'com-axios';
import apiMap from './apis';
/**
* api(必填项): 向后端请求的url 的一种映射,详见demo中的apis.js文件
* data(非必填): 请求参数
* method(非必填): 请求方式,默认为 get
* apiMap(非必填): url映射 键值对
* baseURL(非必填): axios 默认网址,当api为 绝对地址('http://....')时,会覆盖baseURL,不是时baseURL会添加在api前面
*/
comAxios({
api: 'test',
method: 'get',
apiMap,
baseURL: 'http://localhost:9000' // 此时baseURL没有用
}).then((res) => {
alert(`成功返回请求值(${res})`);
console.log(res);
this.setState({
res
})
});
```
## demo 示例
```
// 启动 demo 前端示例
npm start
// 启动 demo 后端服务
npm run server
```