A
A
Andrew2021-11-27 01:10:00
JavaScript
Andrew, 2021-11-27 01:10:00

Is it possible to reactively receive Vuex changes in an external js file?

There was a need to get the state of the store inside a separate class, but since the store is empty during class initialization, there is no necessary data in the class either. Is it possible to get data reactively inside the class? I do not want to duplicate the logic of loading and processing data and load the system with additional api calls.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
S
Sergey Sokolov, 2021-11-27
@AndrewRusinas

You can write a plugin function for the Vuex store. In it, listen to mutation events and do something, for example, inform the left class that there is news.
Example: a function subscribes to store mutations. When the page is loaded, an Action is launched in the store, which simulates the asynchronous loading of something in 1 second (increments the counter).

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question