1 // 将axios再次封装
2 import axios from 'axios'; // npm i -S axios
3
4 import Qs from 'qs' // npm i -S qs
5
6 // 提示组件 mint-ui 中的提示组件
7
8 axios.defaults.withCredentials = true; // false 不跨域 true 跨域
9 axios.defaults.headers.common["token"] = localStorage.getItem('token'); // 这是设置请求头 不是必须的
10
11 export default function(path, params, method = "GET", headerType = "json") {
12 let baseURL = "/api";
13 let data = {}; // 将参数解析出来进行放置的地方
14 // 设置请求头
15 if(method == "post") { // post请求
16 if(headerType == "json") {
17 axios.defaults.headers.post["Content-Type"] =
18 "application/json;charset=utf-8";
19 data = params;
20 } else if(headerType == "multipart") {
21 axios.defaults.headers.post["Conten
axios 的二次封装及使用
最新推荐文章于 2024-06-12 15:37:27 发布
![](https://img-home.csdnimg.cn/images/20240711042549.png)