I did several VUE projects, but I didn’t use VUEX all the time, and I was always worried that I would use it someday. So I secretly paddled a wave of water to learn VUex during working hours.
As the official documentation has made it quite clear, this article is only for my personal understanding notes.
Look at the components
  • State ==> is approximately equal to data in the component, storing data
  • Mutations ==> is approximately equal to synchronous methods and commit trigger events in the component
  • Actions ==> is approximately equal to asynchronous events in the component, and dispatch triggers events
  • Getters ==> is approximately equal to computed in the component
export default new Vuex.Store({
  state: {//data
    name:'zs'
  },
  mutations: {// Synchronize methods commit trigger
    changeName(state,str){
      return state.name+=str
    }
  },
  actions: {// Asynchronous methods dispatch trigger
  },
  getters: {//computed
  },
  modules: {//}})Copy the code
And mapState vuex, mapMutations, auxiliary function such as mapGetters to let me be lazy, after mastering the basic usage, want to spend more time fishing buddy can set the official document (with the people all say good ~)
Last but not least, modules. When there are enough modules in the project and too much data needs to be stored and processed, it will be bloated if they are all written together. Different modules can be divided into a single file, and each module has its own state, mutation, action and getter.