Vue2.7 + Vite+ Eslint、Stylelint、Commitlint 统一开发规范
+ husky + lint-staged (git commit 时自动格式化代码)
+ Vue 全家桶集成
+ Axios 封装及接口管理
https://juejin.cn/post/7118700020911570974
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
20 lines
770 B
20 lines
770 B
2 years ago
|
# Axios 封装及接口管理
|
||
|
|
||
|
这里接口请求使用的是基于 Promise 封装的请求库 [Axios](https://axios-http.com/zh/),也是现在使用很广泛的一个请求库。
|
||
|
|
||
|
## 目录说明
|
||
|
|
||
|
有关请求库的功能都在以下的目录中。
|
||
|
|
||
|
```sh
|
||
|
.
|
||
|
├── src # 主目录
|
||
|
│ ├── api # api 方法配置
|
||
|
│ │ └── demo.js # 演示方法
|
||
|
│ └── utils # 公共方法
|
||
|
│ └── request.js # axios 请求库二次封装
|
||
|
```
|
||
|
|
||
|
在开发时,我们先在 `utils/requset.js` 中配置好适合自己业务的请求拦截和响应拦截。
|
||
|
|
||
|
之后在 `api` 文件夹中定义请求方法,这里我一般会以功能进行拆分,同一个功能的请求方法封装在一个文件,之后在需要的地方进行调用。
|