// hooks/useRequest.ts import { ref } from 'vue' interface IUseRequestOptions { immediate?: boolean initialData?: T } export function useRequest( func: () => Promise, options: IUseRequestOptions = { immediate: false }, ) { const loading = ref(false) const error = ref(null) const data = ref(options.initialData) const run = async () => { loading.value = true error.value = null try { const res = await func() data.value = res return res } catch (err) { error.value = err throw err } finally { loading.value = false } } options.immediate && run() return { loading, error, data, run } }