Asyncdata Vs Fetch
AsyncData is a method that lets you handle async operations
before setting the component data when you want to fetch data and render it on
the server-side. It is called every time before the component is loaded.
Fetch is a method used to fill the store before rendering
the page but it doesn’t set the component data. It is called every time before
navigating to the corresponding route.
AsyncData can access the vuex store and set component level
objects whereas fetch can also access vuex store but cannot set component level
objects.
AsyncData and fetch will be triggered in server-side during
initial load.
Both will be triggered after the initial load and when the
corresponding page routes are invoked.
Choosing asyncData or fetch totally depends on your
architecture.
If your design use vuex store as a central repository you
can use either asyncData or fetch.
If your design uses access data from the vuex store for the
entire application use fetch.
If your design have options to set component level objects
and the data fetched in a particular route is used only by a single component
is asyncData.
Comments
0 comments
Please Sign in or Create an account to Post Comments