import { ref, readonly, type Ref } from 'vue' export function useApiRequest(fetcher: (...args: any[]) => Promise) { const data: Ref = ref(null) const loading = ref(false) const error = ref(null) async function execute(...args: any[]): Promise { 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 } }