# wzn-api

> 项目公共 ajax 请求库,基于 axios，vue,react 中都适用

Latest version **1.3.10** (published 2020-06-26) · ISC license · 0 weekly downloads

## Install

```sh
npm install wzn-api
pnpm add wzn-api
yarn add wzn-api
bun add wzn-api
```

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.3.10 |
| Published | 2020-06-26 |
| First published | 2018-03-18 |
| Weekly downloads | 0 |
| License | ISC |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 1 |
| Unpacked size | 10 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Author | 'Ernest wang' |
| Maintainers | wzn |
| Keywords | 封装ajax请求 |

## Links

- npm: https://www.npmjs.com/package/wzn-api
- Repository: https://github.com/ErnestWangZuNian/project-request-api
- Homepage: https://github.com/ErnestWangZuNian/project-request-api#readme
- Issues: https://github.com/ErnestWangZuNian/project-request-api/issues
- npm.io page: https://npm.io/package/wzn-api

## Dependencies (1)

- [uglifyjs-webpack-plugin](https://npm.io/package/uglifyjs-webpack-plugin.md) ^2.2.0

## Recent versions

- 1.3.10 (latest) — 2020-06-26
- 1.3.9 — 2020-06-26
- 1.3.8 — 2020-06-26
- 1.3.7 — 2018-03-22
- 1.3.6 — 2018-03-22
- 1.3.5 — 2018-03-22
- 1.3.4 — 2018-03-21
- 1.3.3 — 2018-03-21
- 1.3.2 — 2018-03-21
- 1.3.1 — 2018-03-18
- 1.3.0 — 2018-03-18
- 1.2.0 — 2018-03-18
- 1.1.0 — 2018-03-18

## README

# wzn-api

项目公共 ajax 请求库,基于 axios，vue,react 中都适用

> 目的：提高工作效率，少做一些无用功

---

业务开发过程中，我们会经常用到 ajax 请求，axios 已经给我们提供很多便利的方法，为了在实际项目开发中保持代码一致性，结构一致性，错误统一处理，拦截统一处理，为此简单的处理了一下

---

## 安装使用

> 1：使用 npm 安装

## npm

> npm install --save-dev wzn-api
> 使用 import utils from 'wzn-api

## API 文档

[get 参数(url,data)](https://github.com/ErnestWangZuNian/project-request-api/blob/master/src/index.js) get 请求 </br>

[post 参数(url,data)](https://github.com/ErnestWangZuNian/project-request-api/blob/master/src/index.js) psot 请求 </br>

[all 参数(array)](https://github.com/ErnestWangZuNian/project-request-api/blob/master/src/index.js) 多个请求并发 </br>

[create 参数(array)](https://github.com/ErnestWangZuNian/project-request-api/blob/master/src/index.js) 创建一个 axios 实例 </br>

## 使用方式

```js
import Api from "wzn-api";
// 实例化api
let api = new Api();
// 创建实例自己的拦截器
let instance = api.create();
// 添加请求拦截器
instance.interceptors.request.use(
  config => {
    return config;
  },
  error => {
    return Promise.reject(error);
  }
);

// 添加响应拦截器
instance.interceptors.response.use(
  response => {
    return response.data;
  },
  error => {
    // 对响应错误做点什么
    return Promise.reject(error);
  }
);
api.get(url, data).then(data => {
  console.log(data);
});
api.post(url, data).then(data => {
  console.log(data);
});
api.all([api.get(url.data), api.get(url1.data1)]).then(datas => {
  console.log(datas);
});
```

## 参考地址

axios 中文文档 https://www.kancloud.cn/yunye/axios/234845 </br>
另一个项目 react 基础环境搭建里面有 api 的使用方式 https://github.com/ErnestWangZuNian/react-in-project.git

---
_Source: https://npm.io/package/wzn-api · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
