From d04d598ceb029eb26fc20518aafebbd6ddd24edb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=96z=C3=BCm=20Eldo=C4=9Fan?= Date: Mon, 20 Mar 2023 12:13:21 +0300 Subject: [PATCH] docs: avoid `$fetch` in top-level ` +``` + +**/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 `