San3yuan | 4d0e803 | 2025-04-04 17:21:40 +0800 | [diff] [blame^] | 1 | import axios, { AxiosRequestConfig, AxiosResponse } from 'axios' |
| 2 | import instance from './axios' |
| 3 | |
| 4 | // 封装基础请求方法 |
| 5 | const request = { |
| 6 | get<T = any>(url: string, config?: AxiosRequestConfig): Promise<T> { |
| 7 | return instance.get(url, config) |
| 8 | }, |
| 9 | |
| 10 | post<T = any>( |
| 11 | url: string, |
| 12 | data?: any, |
| 13 | config?: AxiosRequestConfig |
| 14 | ): Promise<T> { |
| 15 | return instance.post(url, data, config) |
| 16 | }, |
| 17 | |
| 18 | put<T = any>(url: string, data?: any, config?: AxiosRequestConfig): Promise<T> { |
| 19 | return instance.put(url, data, config) |
| 20 | }, |
| 21 | |
| 22 | delete<T = any>(url: string, config?: AxiosRequestConfig): Promise<T> { |
| 23 | return instance.delete(url, config) |
| 24 | } |
| 25 | } |
| 26 | |
| 27 | // 开发环境启用 Mock |
| 28 | if (process.env.NODE_ENV === 'development') { |
| 29 | require('../mock') // 你的 Mock 配置文件 |
| 30 | } |
| 31 | |
| 32 | |
| 33 | export default request |