Files
backend/frontend/src/composables/useApiRequest.ts
T
34047007@qq.com a6cd99a4ca
CI / backend (push) Canceled after 0s
CI / frontend (push) Canceled after 0s
feat: initial commit - oncology literature search platform
OncoLit: a multi-tenant oncology literature search, feed, and
collaboration platform. Built with FastAPI + Vue 3 + PostgreSQL.
Includes PubMed pipeline, drug approvals, AI summaries, and
systematic review tools.
2026-07-27 07:59:18 +08:00

26 lines
737 B
TypeScript

import { ref, readonly, type Ref } from 'vue'
export function useApiRequest<T>(fetcher: (...args: any[]) => Promise<T>) {
const data: Ref<T | null> = ref(null)
const loading = ref(false)
const error = ref<string | null>(null)
async function execute(...args: any[]): Promise<T | null> {
loading.value = true
error.value = null
try {
const result = await fetcher(...args)
data.value = result
return result
} catch (e: any) {
const msg = e?.response?.data?.detail || e?.message || '请求失败'
error.value = msg
return null
} finally {
loading.value = false
}
}
return { data: readonly(data), loading: readonly(loading), error: readonly(error), execute }
}