diff --git a/docs/content/3.api/1.composables/use-fetch.md b/docs/content/3.api/1.composables/use-fetch.md index dd61bc6bca2..e7febbc889b 100644 --- a/docs/content/3.api/1.composables/use-fetch.md +++ b/docs/content/3.api/1.composables/use-fetch.md @@ -69,12 +69,31 @@ By default, Nuxt waits until a `refresh` is finished before it can be executed a ## Example ```ts -const { data, pending, error, refresh } = await useFetch( - 'https://api.nuxtjs.dev/mountains', - { +const { data, pending, error, refresh } = await useFetch('https://api.nuxtjs.dev/mountains',{ pick: ['title'] +}) +``` + +Using [interceptors](https://github.com/unjs/ohmyfetch#%EF%B8%8F-interceptors): + +```ts +const { data, pending, error, refresh } = await useFetch('/api/auth/login', { + onRequest({ request, options }) { + // Set the request headers + options.headers = options.headers || {} + options.headers.authorization = '...' + }, + onRequestError({ request, options, error }) { + // Handle the request errors + }, + onResponse({ request, response, options }) { + // Process the response data + return response._data + }, + onResponseError({ request, response, options }) { + // Pandle the response errors } -) +}) ``` :ReadMore{link="/guide/features/data-fetching"}