fetch Hook

In this example we use the fetch hook to fetch data from components and from pages


In this example:

pages/index.vue imports components/Mountains.vue which uses the fetch hook and the $http module to fetch our data at component level while pages/mountains/_slug fetches the data at page level and include:

  • $fetchState.pending to show a loading text when the data is loading.
  • $fetchState.error to show an error message when we can't retrieve the data.
  • $fetch to fetch the data again when clicked.
Loading Sandbox...
Editer cette page sur GitHub Mise à jour le Mon, July 12, 2021