refactor: refactor useAxios
This commit is contained in:
@@ -6,22 +6,41 @@ import { config } from '@/config/axios/config'
|
||||
|
||||
const { default_headers } = config
|
||||
|
||||
export const useAxios = () => {
|
||||
const request = <T>(option: AxiosConfig): AxiosPromise<T> => {
|
||||
const { url, method, params, data, headersType, responseType } = option
|
||||
return service({
|
||||
url: url,
|
||||
method,
|
||||
params,
|
||||
data,
|
||||
responseType: responseType,
|
||||
headers: {
|
||||
'Content-Type': headersType || default_headers
|
||||
}
|
||||
})
|
||||
}
|
||||
const request = <T>(option: AxiosConfig): AxiosPromise<T> => {
|
||||
const { url, method, params, data, headersType, responseType } = option
|
||||
return service({
|
||||
url: url,
|
||||
method,
|
||||
params,
|
||||
data,
|
||||
responseType: responseType,
|
||||
headers: {
|
||||
'Content-Type': headersType || default_headers
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
function getFn<T = any>(option: AxiosConfig): AxiosPromise<T> {
|
||||
return request<T>({ method: 'get', ...option })
|
||||
}
|
||||
|
||||
function postFn<T = any>(option: AxiosConfig): AxiosPromise<T> {
|
||||
return request<T>({ method: 'post', ...option })
|
||||
}
|
||||
|
||||
function deleteFn<T = any>(option: AxiosConfig): AxiosPromise<T> {
|
||||
return request<T>({ method: 'delete', ...option })
|
||||
}
|
||||
|
||||
function putFn<T = any>(option: AxiosConfig): AxiosPromise<T> {
|
||||
return request<T>({ method: 'put', ...option })
|
||||
}
|
||||
|
||||
export const useAxios = () => {
|
||||
return {
|
||||
request
|
||||
get: getFn,
|
||||
post: postFn,
|
||||
delete: deleteFn,
|
||||
put: putFn
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user