A
A
Anton Anton2017-08-10 19:54:33
JavaScript
Anton Anton, 2017-08-10 19:54:33

$emit equivalent for vuex modules?

I break a large state into modules and ran into a problem: there is a piece, conditionally user (information about the user, methods for entering and exiting), on which all other modules "depend". For example, when logging in, all dependent data should be loaded. It turns out that some analogue of emit is needed in order to call the method of the storage root from the user module, which would cause the loading of all data. It turns out that everything connected with the user will have to be left at the root?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
J
JSmitty, 2017-08-10
@JSmitty

And the subscribe function of the store will not solve your problem? Subscribe to mutations with some kind of observer, and upon the arrival of a certain mutation that changes the user, cascade dispatch actions to change the associated data.
Or through watch on a specific user data block, similarly.
It is described in the documentation poorly, see the API Reference section

F
furrya_black, 2017-08-11
@furrya_black

Subscribing to mutations solves your problem.
Dispatch the necessary actions that fill the states of other modules. Use watchers and getters in components.
If you don't understand something, it won't work. Write, in the evening I will be at home according to Moscow time, I will throw an example.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question