在mutation中写上自定义的方法,组件中通过 this.$store.commit(“自定义的方法名”) 就可以更新store中的数据和状态

vueX mutation

  1. 直接取值:
    <div>{{$store.state.count}}</div>
  2. 通过methods操作值:
    addCount(){this.$store.commit('increment')},
  3. 通过methods传值
    addnum(addcounter){ this.$store.commit("addIncrement",addcounter)},

相关文章: