import type { AxiosResponse } from 'axios'; import type { HttpResponse } from '@/api/interceptor'; import type { UnwrapRef } from 'vue'; import { ref } from 'vue'; import useLoading from './loading'; export default function useRequest( api: () => Promise>, defaultValue = [] as unknown as T, isLoading = true ) { const { loading, setLoading } = useLoading(isLoading); const response = ref(defaultValue); api().then((res) => { response.value = res.data as unknown as UnwrapRef; }).finally(() => { setLoading(false); }); return { loading, response }; }