Fetching Data with useFetch and Matching HTTP Methods
Learn how to use the useFetch composable and work with different HTTP methods.
We'll cover the following...
When requesting data from our server so far, we have used the $fetch
helper:
Press + to interact
const data = await $fetch('/api/posts')
The useFetch
composable
We can also use other Nuxt data-fetching composables including useFetch()
:
Press + to interact
const data = await useFetch("/api/posts");
This will also fetch the data from the provided URL. Behind the scenes, useFetch
is a wrapper around the $fetch
helper and useAsyncData
.