Welcome toVigges Developer Community-Open, Learning,Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
481 views
in Technique[技术] by (71.8m points)

使用Vuex中的 mapMutations 辅助函数时怎么传递参数(Payload)

用this.$store.commit('xxx',obj)时可以传递一个obj,那么用mapMutations()时怎么传递一个额外的参数。
并没有在官方文档上找到方法,难道mapMutations里面只能放没有传递额外参数的方法吗?
按道理讲不应该啊,既然提供了简便的方法好歹服务到位吧。

**使用 this.$store.commit()时** 两种格式都能提交附加的数据

方法一:
store.commit('increment', {
  amount: 10
})

方法二:
store.commit({
  type: 'increment',
  amount: 10
})



**使用mapMutations()时** 就没发现有提交的位置

import { mapMutations } from 'vuex'

export default {
  // ...
  methods: {
    ...mapMutations([
      'increment' // 映射 this.increment() 为 this.$store.commit('increment')
    ]),
    ...mapMutations({
      add: 'increment' // 映射 this.add() 为 this.$store.commit('increment')
    })
  }
}

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

this.increment({ amount: 10 })this.add({ amount: 10 })


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to Vigges Developer Community for programmer and developer-Open, Learning and Share

2.1m questions

2.1m answers

63 comments

56.6k users

...