first commit

This commit is contained in:
编码猿
2024-09-27 02:06:13 +08:00
commit 852d94fbb9
36760 changed files with 3274413 additions and 0 deletions

View File

@@ -0,0 +1,73 @@
import axios from "axios";
import config from "@/config"
import { Toast } from 'vant';
export default class Http {
constructor() {
console.log(config.CheckBaseUrl());
this.instance = axios.create({
baseURL: config.CheckBaseUrl(),
timeout: 10000,
headers: {
"Content-Type": "application/json; charset=utf-8"
}
});
this.interceptors();
}
async get(params) {
return await this.instance.get(params.url, {
params: params.data,
headers: params.headers
})
}
async post(params) {
return await this.instance.post(params.url, params.data, {
headers: params.headers
})
}
interceptors() {
// 添加请求拦截器
this.instance.interceptors.request.use(function (config) {
Toast.loading({
duration: 0,
message: '加载中...'
})
return config;
}, function (error) {
// 对请求错误做些什么
return Promise.reject(error);
});
// 添加响应拦截器
this.instance.interceptors.response.use(function (response) {
Toast.clear()
switch (response.data.status) {
case 200:
return response.data.result
break;
case 404:
Toast.fail({
duration: 3000,
message: response.data.message
})
throw new Error(response.data.message);
break;
default:
break;
}
return response.data;
}, function (error) {
// 对响应错误做点什么
return Promise.reject(error);
});
}
}