NuxtN
Nuxt3mo ago
3 replies
Zhaolin Lau

custom uselazyfetch

codes below are my custom usefetch, how to make a uselazyfetch?

import type { UseFetchOptions } from '#app'

export const useAPI = <T>(
url: string | (() => string),
options?: UseFetchOptions<T>,
) => {
return useFetch(url, {
...options,
$fetch: useNuxtApp().$api as typeof $fetch,
})
}
Was this page helpful?