🌿 Nuxt.js
Beginner
What is `useFetch` in Nuxt.js?
Answer
useFetch is a convenience wrapper around useAsyncData and Nuxt's $fetch utility that combines both in a single composable specifically designed for HTTP requests. It automatically generates the cache key from the URL and options, making it simpler than useAsyncData for direct API calls. Usage: const { data, pending, error } = await useFetch('/api/users'). It supports options like method, body, headers, query, lazy, and watch. The lazy option defers the fetch until after navigation, useful for non-critical data.
Previous
What is `useAsyncData` in Nuxt.js?
Next
What is the `components/` directory auto-import feature?