Refactor API requests and update imports
This commit is contained in:
@ -35,14 +35,14 @@ const useClientRequest = async <T = unknown>(
|
||||
|
||||
// 明确转换返回类型
|
||||
const response = await $fetch(url, { ...defaultOptions, ...opts });
|
||||
return response as unknown as IResponse<T>;
|
||||
return response as unknown as T;
|
||||
};
|
||||
|
||||
// GET请求
|
||||
export const get = <T = unknown>(
|
||||
endpoint: string,
|
||||
config?: Omit<FetchOptions, 'method'>
|
||||
): Promise<IResponse<T>> => {
|
||||
): Promise<T> => {
|
||||
return useClientRequest<T>(endpoint, { ...config, method: 'GET' })
|
||||
}
|
||||
|
||||
@ -51,7 +51,7 @@ const useClientRequest = async <T = unknown>(
|
||||
endpoint: string,
|
||||
body?: any,
|
||||
config?: Omit<FetchOptions, 'method' | 'body'>
|
||||
): Promise<IResponse<T>> => {
|
||||
): Promise<T> => {
|
||||
return useClientRequest<T>(endpoint, { ...config, method: 'POST', body })
|
||||
}
|
||||
|
||||
@ -60,7 +60,7 @@ const useClientRequest = async <T = unknown>(
|
||||
export const del = <T = unknown>(
|
||||
endpoint: string,
|
||||
config?: Omit<FetchOptions, 'method'>
|
||||
): Promise<IResponse<T>> => {
|
||||
): Promise<T> => {
|
||||
return useClientRequest<T>(endpoint, { ...config, method: 'DELETE' })
|
||||
}
|
||||
|
||||
@ -69,6 +69,6 @@ const useClientRequest = async <T = unknown>(
|
||||
endpoint: string,
|
||||
body?: any,
|
||||
config?: Omit<FetchOptions, 'method' | 'body'>
|
||||
): Promise<IResponse<T>> => {
|
||||
): Promise<T> => {
|
||||
return useClientRequest<T>(endpoint, { ...config, method: 'PUT', body })
|
||||
}
|
||||
Reference in New Issue
Block a user