为了账号安全,请及时绑定邮箱和手机立即绑定

Vuex 中的mapActions怎么传递自定义参数????????

Vuex 中的mapActions怎么传递自定义参数????????

君临天下0123 2019-05-28 21:23:46
---------------------store.js-----------------------------------const store = new Vuex.Store({state: {count: 100000000},getters: {getChangedNum () {// eslint-disable-next-line no-undefreturn state.count}},mutations: {newNum (state, sum) {state.count += sum}},actions: {getNewNum (context, num) {context.commit('newNum', num)}}})----------------组件-----------------------<button @click="getNewNum">add</button>methods: {add () {this.$store.commit('newNum', 1)      // 调用mutationsthis.$store.dispatch('getNewNum', 1)   // 调用actions , }...mapActions({  add: 'getNewNum'      //如果使用mapActions, 这里怎么要传递这个‘1’ })}
查看完整描述

3 回答

?
pardon110

TA贡献1038条经验 获得超227个赞

...mapActions({
      add: 'getNewNum' // 将 `this.add()` 映射为 `this.$store.dispatch('getNewNum')`
    })

在 组件中进行这样调用

this.add(1)

将被映射为如下调用

this.$store.dispatch('getNewNum', 1)


查看完整回答
1 反对 回复 2019-06-18
  • 3 回答
  • 0 关注
  • 6675 浏览
慕课专栏
更多

添加回答

举报

0/150
提交
取消
意见反馈 帮助中心 APP下载
官方微信