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

---------------------store.js-----------------------------------

const store = new Vuex.Store({

state: {

count: 100000000

},

getters: {

getChangedNum () {

// eslint-disable-next-line no-undef

return 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)      // 调用mutations

this.$store.dispatch('getNewNum', 1)   // 调用actions ,

 }

...mapActions({

  add: 'getNewNum'      //如果使用mapActions, 这里怎么要传递这个‘1’

 })

}


君临天下0123
浏览 6724回答 3
3回答

pardon110

...mapActions({       add: 'getNewNum' // 将 `this.add()` 映射为 `this.$store.dispatch('getNewNum')`     })在 组件中进行这样调用this.add(1)将被映射为如下调用this.$store.dispatch('getNewNum', 1)
打开App,查看更多内容
随时随地看视频慕课网APP