Complete Vue.js 2 Web Development_ Practical guide to building end-to-end web development solutions with Vue.js 2

(singke) #1
State Management with Vuex Chapter 21

Whenever the user clicks on a button, an action is dispatched from within one of the


following methods:


import * as types from './store/mutation-types';

export default {
methods: {
increment() {
this.$store.dispatch(types.INCREMENT);
},
decrement() {
this.$store.dispatch(types.DECREMENT);
},
reset() {
this.$store.dispatch(types.RESET);
},
},
}

Once again, we're using constants to make for a better development experience. Next, in


order to take advantage of the getter we created earlier, let's define a computed property:


export default {
// Omitted
computed: {
count() {
return this.$store.getters.count;
},
},
}
Free download pdf