Quickly learn to use Vuex

A, Vuex Profile

Official definition

  • Vuex is a specialized Vue.js application on state management
  • It uses all the components of the centralized storage management application state
  • And a corresponding rule ensures a predictable manner changes

Second, the application scenarios

  • A plurality of views dependent to the same state
  • Behavior needs to change from a different view of the same state

Three, Vuex installation and composition of the introduction of

  • State - data warehouse stores all data states
  • Getter - used to obtain data
  • Mutation - used to modify the data, the synchronization
  • Action - to submit mutation , asynchronous

  installation

  • Installation vuex package: npm install vuex
  • Creating vuex Examples: new new Vuex.store ()
  • Main.js will vuex instance mount vue on the object

 

Attaining count ++

  • State created in the count field
  • Mutations create a count ++ of mutation
  • Button added click event triggering mutation to change the count

 

 

Core code

  App.vue

  

 

   main.js

  

 

Guess you like

Origin www.cnblogs.com/le220/p/11612418.html