Answer the question
In order to leave comments, you need to log in
How to understand whether Vuex is needed or not?
Good evening, I'm trying to understand in what situations you need to use Vuex, the most obvious and logical is to save the user's state, since many components need it.
But for example, I make a blog, everywhere in the examples and lessons, even the usual blog structure is shoved into vuex and posts are already being output from vuex. This is where my question arises, why?
Why can't you just display posts via axios in the component itself?
Please describe someone how to correctly understand when to use Vuex?
Answer the question
In order to leave comments, you need to log in
even the usual blog structure is shoved into vuex and posts are already being pulled out of vuex. This is where my question arises, why?
You got it right!
State stores/notifies changes to the overall state of the application. There is no need to shove what should be stored in a component or a group of components.
In your example, the blog page is the component that stores the articles, and passes the data to be displayed to the article component.
If you need to cache articles on the client, then you need to use some other techniques for this, and not clog the reactive storage with unnecessary data.
A clear example of a correct usage would be the theme of an application, where many components subscribe to its change and change their behavior depending on the data received.
Or part of the paths on the site disappears or appears from the user's role.
In general, you are on the right path, comrade!
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question