common.js
1.1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
import Axios from "axios";
// 请求拦截
Axios.interceptors.request.use(
function(config) {
return config;
},
function(err) {
return Promise.reject(error);
}
);
// 响应拦截
Axios.interceptors.response.use(
function(response) {
//对响应数据做事情
console.log("请求成功", response);
if (response.data.code == 1) {
return response.data;
} else {
return Promise.reject(response.data);
}
},
function(error) {
console.log(error);
return Promise.reject(error.response.data);
}
);
export default Axios;
export function uploadFile(Url, data) {
//上传图片的方法
return new Promise((resolve, reject) => {
let instance = axios.create({
baseURL: "http://ht.tayoji-health.com/api/",
headers: {
"Content-Type": "multipart/form-data"
}
});
instance
.post(Url, data)
.then(res => {
resolve(res.data.data);
})
.catch(error => {
reject(error.data);
});
});
}