hook-fetch
Version:
A lightweight and modern HTTP request library developed based on the native Fetch API of the browser, providing a user-friendly interface similar to Axios and powerful extensibility.
33 lines (32 loc) • 1.89 kB
TypeScript
import { HookFetchRequest } from '../utils';
interface UseHookFetchOptions<Q extends (...args: any[]) => any> {
request: Q;
onError?: (e: Error) => any;
}
/**
* Hook fetch composable function | Hook fetch 组合式函数
* @param options - Hook fetch options | Hook fetch 选项
* @param options.request - Request function | 请求函数
* @param options.onError - Error callback function | 错误回调函数
* @returns {Function} request - Request function | 请求函数
* @returns {Function} cancel - Cancel request | 取消请求
* @returns {Ref<boolean>} loading - Loading state | 加载状态
* @returns {Function} text - Get response as text | 获取文本响应
* @returns {Function} stream - Get response as stream | 获取流响应 | 获取流响应
* @returns {Function} blob - Get response as blob | 获取二进制响应
* @returns {Function} arrayBuffer - Get response as array buffer | 获取二进制缓冲区响应
* @returns {Function} formDataResult - Get response as form data | 获取表单数据响应
* @returns {Function} bytesData - Get response as bytes | 获取字节数据响应
*/
export declare const useHookFetch: <Q extends (...args: any[]) => any>({ request, onError }: UseHookFetchOptions<Q>) => {
request: (...args: any[]) => HookFetchRequest<any, any> | null;
stream: (...args: Parameters<Q>) => AsyncGenerator<import('..').StreamContext<unknown> | import('..').StreamContext<null>, import('../utils').ResponseError<unknown> | undefined, unknown>;
text: (...args: Parameters<Q>) => Promise<any>;
blob: (...args: Parameters<Q>) => Promise<any>;
arrayBufferData: (...args: Parameters<Q>) => Promise<any>;
formDataResult: (...args: Parameters<Q>) => Promise<any>;
bytesData: (...args: Parameters<Q>) => Promise<any>;
cancel: () => void;
loading: import('vue').Ref<boolean, boolean>;
};
export {};