vuex(1)

属性:mutation

作用:用于直接修改state

用法:this.$store.commit("increment")

携参:this.$store.commit("increment”,’Hannah’)

 

属性:action

作用:通过提交mutation 改变state

用法:this.$store.dispatch("increment")

携参:this.$store.dispatch("increment”,’Hannah’)

 

注解:Module

每个module都可以有自己的state ,mutations,actions,getters,比如:

const moduleA = {

  state: { ... },

  mutations: { ... },

  actions: { ... },

  getters: { ... }

}

const moduleB = {

  state: { ... },

  mutations: { ... },

  actions: { ... },

  getters: { ... }

}

 

放入仓库:

const store = new Vuex.Store({

  modules: {

    a: moduleA,

    b: moduleB

  }

})

 

取值:

store.state.a // -> moduleA 的状态

store.state.b // -> moduleB 的状态

 

但行好事,莫问前程。
原文地址:https://www.cnblogs.com/txhy/p/11483469.html