export const myFetch = $fetch.create({ onRequest({ request, options }: any) { const token = useCookie('token') const { apiBase, apiPrefix } = useRuntimeConfig() request = apiPrefix + request options.headers = options.headers || {} options.baseURL = apiBase const option = options as any option.headers.Authorization = token.value || undefined }, onRequestError({ request, options, error }) { // Handle the request errors }, onResponse({ request, response, options }) { // Process the response data return response._data }, onResponseError({ request, response, options }) { // Handle the response errors } }) export const RemoteApi = { get: (url: string, params?: any) => { return myFetch>(url, { method: 'get', params }) }, post: (url: string, body?: any) => { return myFetch>(url, { method: 'post', body }) }, put: (url: string, body?: any) => { return myFetch>(url, { method: 'put', body }) }, delete: (url: string, body?: any) => { return myFetch>(url, { method: 'delete', body }) } }