I have created a basic store in my store/index.js file with the following structure:
export const state = () => ({
isDark: false,
});
export const mutations = {
setIsDark(state, payload) {
state.isDark = payload;
},
};
export const getters = {
getIsDark(state) {
return state.isDark;
},
};
Although I am able to access the value of isDark in my component, I encounter an error when trying to call the setIsDark method:
TypeError: Cannot read property 'setIsDark' of undefined
Here is how my component is structured:
computed: {
isDark() {
return this.$store.getters.getIsDark;
},
},
methods: {
toggleIsDark() {
this.$store.mutations.setIsDark(!this.isDark);
},
},
Can anyone point out what might be causing this issue?