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,66 @@
import axios from 'axios'
import config from '@/config/index'
import { Toast } from 'vant';
class Http {
constructor() {
this.instance = axios.create({
baseURL: config.checkBaseUrl(),
timeout: 3000,
headers: {}
});
this.interceptors()
}
// { url: '/index', data: { id: 1, page: 1 } }
async get(params) {
return await this.instance.get(params.url, {
params: params.data
})
}
async post(params) {
return await this.instance.post(params.url, params.data)
}
interceptors() {
// 添加请求拦截器
this.instance.interceptors.request.use(function (config) {
Toast.loading({
message: '加载中...',
duration: 0,
});
// 在发送请求之前做些什么
return config;
}, function (error) {
// 对请求错误做些什么
return Promise.reject(error);
});
// 添加响应拦截器
this.instance.interceptors.response.use(function (response) {
Toast.clear();
switch (response.data.resultCode) {
case "000":
return response.data.data;
break;
case "500":
Toast.loading({
type: 'fail',
message: response.data.message
});
throw new Error(response.data.message)
break;
default:
break;
}
}, function (error) {
// 对响应错误做点什么
return Promise.reject(error);
});
}
}
export default Http;