Is there any other way to fetch data instead of prefetch in vue hacker news

447 views Asked by At

I am writing a vue spa with vue ssr.

According to the office guide, data in component will be prefetch server side and store in a vuex store.

This seems complicated. So i want to know is there any possible way to fetch data, which can keep data just in a component itself? No need a vuex store or any other third party storage.

1

There are 1 answers

0
pate On

Yes there is.

You can do whatever you want in each component's own mounted/created/etc. hooks. This would most likely be an appropriate place to fetch data from the network and then display it to the user. You would probably show a loading spinner by default and disable it when the data arrives. You would store the received data in the component's local data.

Without Vuex or other state management solutions and only using components, however, the fetched data will be local to your component. Thus switching out the component loses the data and will require a new network fetch and so on.