How to keep the data Synchronize when multiple components of Vue use the same data?

example:

there are resource lists, builds, army lists, and other components in the game, all of which require resource variables.

build reduces the number of resource values. How does this change spread to other components?

the current solution is to define a localStorage resource , which is obtained by the highest-level component and passed to the low-level component, and then the low-level component uses created to reconstruct data (when the resource attribute of the parent is added)

There are many

components. Although we try our best to maintain the original principle of inheriting at most three levels, a page with more than a dozen components requires resource . Adding a new variable requires more than a dozen pieces of the same code, and the degree of coupling scares me to death.

Libraries already used:

  • the latest version of Vue2
  • the latest version of Vue-Router

is obviously a global problem of modifying and listening to the same state, and vuex is obviously created for this kind of scenario.


vuex
https://vuex.vuejs.org/zh/

Menu