What is Vuex?

VietMX Staff asked 3 years ago

Vuex is a state management pattern + library for Vue.js applications. It serves as a centralized store for all the components in an application, with rules ensuring that the state can only be mutated in a predictable fashion. The basic idea behind Vuex, inspired by Flux, Redux and The Elm Architecture.

Vuex resolves two problems:

  • Multiple views may depend on the same piece of state. Passing props can be tedious for deeply nested components, and simply doesn’t work for sibling components.
  • Actions from different views may need to mutate the same piece of state. We often find ourselves resorting to solutions such as reaching for direct parent/child instance references or trying to mutate and synchronize multiple copies of the state via events. Both of these patterns are brittle and quickly lead to unmaintainable code.