/** * API 호출 유틸리티 composable */ interface ApiOptions { method?: 'GET' | 'POST' | 'PUT' | 'DELETE' body?: any query?: Record } export function useApi() { const isLoading = ref(false) const error = ref(null) /** * API 호출 래퍼 */ async function call(url: string, options: ApiOptions = {}): Promise { isLoading.value = true error.value = null try { const response = await $fetch(url, { method: options.method || 'GET', body: options.body, query: options.query }) return response } catch (err: any) { const message = err.data?.message || err.message || '요청 처리 중 오류가 발생했습니다.' error.value = message throw new Error(message) } finally { isLoading.value = false } } // 편의 메서드들 const get = (url: string, query?: Record) => call(url, { method: 'GET', query }) const post = (url: string, body?: any) => call(url, { method: 'POST', body }) const put = (url: string, body?: any) => call(url, { method: 'PUT', body }) const del = (url: string) => call(url, { method: 'DELETE' }) return { isLoading: readonly(isLoading), error: readonly(error), call, get, post, put, del } }