We can use the mapMutations helper to map the component methods to the mutation methods with object spread operators so that we can mix multiple mapMutations helpers in the method property. Let's see how we can do it with the following steps:
- Import the mapMutations helper from Vuex and pass the mutations as an array to the mapMutations method with object spread operators, as follows:
// vuex-sfc/mutations/mapmutations/src/app.vue
import { mapMutations } from 'vuex'
export default {
computed: {
number () {
return this.$store.state.number
}
},
methods: {
...mapMutations([
'multiply',
'multiplyBy',
'divide'
]),
...mapMutations({
square: 'multiply'
})
}
}
- Add the computed state property and the methods to <template>, as follows:
// vuex-sfc/mutations/mapmutations/src/app.vue
<p>{{ number }}</p>
<p>
<button v-on:click="...