Store.mapMutations

创建组件方法提交 mutation。详细介绍

参数说明
参数 类型 必填 说明
map Array | Object 如果是对象形式,成员可以是一个函数。function(commit: function, ...args: any[])
示例
// store.js
import createStore from 'chameleon-store'
const store = createStore({
  state: {
    count: 0
  },
  mutations: {
    increment (state) {
      state.count++
    }
  }
})

export default store

// app.js
import store from './store.js'
class Index {
  // ...
  methods = {
    ...store.mapMutations([
      'increment', // 将 `this.increment()` 映射为 `this.$store.commit('increment')`
    ]),
    ...store.mapMutations({
      add: 'increment' // 将 `this.add()` 映射为 `this.$store.commit('increment')`
    })
  }
};
export default new Index();

results matching ""

    No results matching ""