Skip to content

Commit

Permalink
nuxt(docs): example in docs
Browse files Browse the repository at this point in the history
  • Loading branch information
adrienZ committed Apr 6, 2023
1 parent 337af5d commit 3a7f42b
Show file tree
Hide file tree
Showing 8 changed files with 31 additions and 6 deletions.
3 changes: 3 additions & 0 deletions docs/3.api/1.composables/use-fetch.md
Expand Up @@ -126,6 +126,9 @@ const { data, pending, error, refresh } = await useFetch('/api/auth/login', {
`useFetch` is a reserved function name transformed by the compiler, so you should not name your own function `useFetch`.
::

::LinkExample{link="/docs/examples/other/use-custom-fetch-composable"}
::

:ReadMore{link="/docs/getting-started/data-fetching"}

::LinkExample{link="/docs/examples/composables/use-fetch"}
Expand Down
9 changes: 9 additions & 0 deletions docs/4.examples/8.other/use-custom-fetch-composable.md
@@ -0,0 +1,9 @@
---
toc: false
---

# Use custom fetch composable

This example shows a convenient wrapper for the useFetch composable from nuxt. It allows you to customize the fetch request with default values and user authentication token.

::sandbox{repo="nuxt/nuxt" branch="main" dir="examples/other/use-custom-fetch-composable" file="composables/useCustomFetch.ts"}
5 changes: 0 additions & 5 deletions examples/other/custom-fetch-composable/app.vue

This file was deleted.

16 changes: 16 additions & 0 deletions examples/other/use-custom-fetch-composable/app.vue
@@ -0,0 +1,16 @@

<script setup lang="ts">
const { data } = await useCustomFetch<object>('/beers')
</script>

<template>
<NuxtExampleLayout example="other/use-custom-fetch-composable">
<h1 class="text-xl opacity-50">
Nuxt custom fetch
</h1>

<pre class="text-left text-xs">{{ data }}</pre>
</NuxtExampleLayout>
</template>
@@ -1,4 +1,6 @@
// https://nuxt.com/docs/api/configuration/nuxt-config
export default defineNuxtConfig({

modules: [
'@nuxt/ui'
]
})

0 comments on commit 3a7f42b

Please sign in to comment.