feat: 重新整理目录结构,mock请求

This commit is contained in:
kailong321200875
2023-11-30 11:34:39 +08:00
parent c8400abd9f
commit 179ab2672f
27 changed files with 96 additions and 112 deletions

38
src/axios/index.ts Normal file
View File

@@ -0,0 +1,38 @@
import service from './service'
import { CONTENT_TYPE } from '@/constants'
const request = (option: AxiosConfig) => {
const { url, method, params, data, headers, responseType } = option
return service.request({
url: url,
method,
params,
data,
responseType: responseType,
headers: {
'Content-Type': CONTENT_TYPE,
...headers
}
})
}
export default {
get: <T = any>(option: AxiosConfig) => {
return request({ method: 'get', ...option }) as Promise<IResponse<T>>
},
post: <T = any>(option: AxiosConfig) => {
return request({ method: 'post', ...option }) as Promise<IResponse<T>>
},
delete: <T = any>(option: AxiosConfig) => {
return request({ method: 'delete', ...option }) as Promise<IResponse<T>>
},
put: <T = any>(option: AxiosConfig) => {
return request({ method: 'put', ...option }) as Promise<IResponse<T>>
},
cancelRequest: (url: string | string[]) => {
return service.cancelRequest(url)
},
cancelAllRequest: () => {
return service.cancelAllRequest()
}
}