1.state中的数据获取时使用 this.$store.state.xxx;
2.修改state中的数据必须通过 mutations 中提供的方法,调用方法使用 this.$store.commit('方法名称', 唯一参数),要传递多个参数可使用对象;
3.如果对外提供 state 中的数据时需要对数据进行包装,可使用 getters,方法为:this.$store.getters.xxx
let store = new Vuex.Store({
    state: {
        theUrl: {},
        count: 0,
    },
    mutations: {
        increment(state, obj) {
        state.count += (obj.a + obj.d)
         }   
     },
    getters: {
        optCount: function (state) {
        return '当前最新的count值是:' + state.count
        }
  },
}

 

相关文章:

  • 2021-04-10
  • 2021-09-01
  • 2021-12-28
  • 2022-12-23
  • 2022-12-23
  • 2022-01-08
  • 2021-10-11
猜你喜欢
  • 2021-05-29
  • 2021-05-16
  • 2021-11-15
  • 2021-12-20
  • 2022-12-23
  • 2021-05-21
相关资源
相似解决方案