diff --git a/docs/1.getting-started/6.data-fetching.md b/docs/1.getting-started/6.data-fetching.md index 3468e30d26..214ffd80a1 100644 --- a/docs/1.getting-started/6.data-fetching.md +++ b/docs/1.getting-started/6.data-fetching.md @@ -219,14 +219,24 @@ Using ` +``` + +**/server/api/product.get.ts**: Server only code below executes `$fetch` only once at the server side. + +```ts +export default eventHandler(async (event: H3Event) => { + const price = $fetch('/api/price'); + return { color: getColor(), price }; +}); +``` + +If fetching twice isn't your intended behavior, to fetch only on the server side and transfer it to the client, wrap `$fetch` with `useAsyncData()` or use `useFetch()`. + +```ts + +``` + ## Using Async Setup If you are using `async setup()`, the current component instance will be lost after the first `await`. (This is a Vue 3 limitation.) If you want to use multiple async operations, such as multiple calls to `useFetch`, you will need to use `