Store.mapMutations

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

参数说明
参数类型必填说明
mapArray | Object如果是对象形式,成员可以是一个函数。function(commit: function, …args: any[])
示例
  1. // store.js
  2. import createStore from 'chameleon-store'
  3. const store = createStore({
  4. state: {
  5. count: 0
  6. },
  7. mutations: {
  8. increment (state) {
  9. state.count++
  10. }
  11. }
  12. })
  13. export default store
  14. // app.js
  15. import store from './store.js'
  16. class Index {
  17. // ...
  18. methods = {
  19. ...store.mapMutations([
  20. 'increment', // 将 `this.increment()` 映射为 `this.$store.commit('increment')`
  21. ]),
  22. ...store.mapMutations({
  23. add: 'increment' // 将 `this.add()` 映射为 `this.$store.commit('increment')`
  24. })
  25. }
  26. };
  27. export default new Index();