I am writing an Electron app using Vue and Vuex.
My store is as follows (counter.js
):
const state = {
main: 5
};
const mutations = { // synchronous tasks
INCREMENT_MAIN_COUNTER (state) {
state.main++;
}
};
const getters = {
count: (state) => {
return state.main;
}
};
export default {
state, getters, mutations
}
My Vue component is as follows (LandingPage.vue
):
<template>
<div id="count-box">
{{count}}
<button @click="pressed">Increment counter</button>
</div>
</template>
<script>
import counter from '../store';
export default {
name: 'landing-page',
computed: {
count: () => {
return counter.getters.count;
}
},
methods: {
pressed: () => {
counter.commit('INCREMENT_MAIN_COUNTER');
}
}
};
</script>
When I click the button to increment, the commit
is called, and the following exception is triggered:
Uncaught Error: [Vuex Electron] Please, don't use direct commit's, use dispatch instead of this.
at Store.store.commit (.../node_modules/vuex-electron/dist/shared-mutations.js:1)
at VueComponent.pressed (LandingPage.vue?b116:20)
at invoker (vue.esm.js?a026:2027)
at HTMLButtonElement.fn._withTask.fn._withTask (vue.esm.js?a026:1826)
I don't understand exactly what could be causing this, as I have been following https://www.youtube.com/watch?v=LW9yIR4GoVU and https://vuex.vuejs.org/guide/mutations.html which appear to be doing it this way.