N
N
nezzard2019-05-17 20:56:13
Vue.js
nezzard, 2019-05-17 20:56:13

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

2 answer(s)
A
AlexanderY, 2019-05-18
@nezzard

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?

Most often because they do not understand what they are doing. If some data is needed only in one place, it makes no sense to put it in a store.
If there is a possibility that in the future this data will be needed somewhere else - yes, you can prepare and add up in advance, then it's up to you to decide in your particular situation.
However, there is another argument why the data can be taken out - to reduce the "cognitive load" on the body of the programmer who opened the component file. Those. just take some of the code out.

A
Andrey K, 2019-05-19
@kuftachev

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 question

Ask a Question

731 491 924 answers to any question