Nuxt.js: Question: difference between fetch and asyncData

Created on 21 Aug 2017  路  4Comments  路  Source: nuxt/nuxt.js

Hi!

It is confusing when to use fetch and when asyncData

They both can:

  • access context (store, params)
  • both can be called from the server-side

If I understand correctly I should use fetch when I want to fill the store and asyncData when I want to set up component data.

But asyncData can access store too. So why there are these two methods?

This question is available on Nuxt.js community (#c1274)

Most helpful comment

@cretueusebiu answer is the one :)

When you need to fetch some data for the store especially for a specific page (like search results), use fetch, otherwise, use asyncData.

It's more for code readability :+1:

All 4 comments

fetch for vuex, asyncData for page data?

Use asyncData only when you need to return data for the current component.

Use fetch when you want to work with the store.

@cretueusebiu answer is the one :)

When you need to fetch some data for the store especially for a specific page (like search results), use fetch, otherwise, use asyncData.

It's more for code readability :+1:

This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

nassimbenkirane picture nassimbenkirane  路  3Comments

vadimsg picture vadimsg  路  3Comments

mikekidder picture mikekidder  路  3Comments

maicong picture maicong  路  3Comments

gary149 picture gary149  路  3Comments