...

/

Fetching Data with useFetch and Matching HTTP Methods

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:

Javascript (babel-node)
const data = await $fetch('/api/posts')

The useFetch composable

We can also use other Nuxt data-fetching composables including useFetch():

Javascript (babel-node)
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.

Changing the HTTP method

We can also ...