I am a complete beginner when it comes to Vuex, and I am currently facing an issue with assigning a value to a Vuex state, specifically state.map.status.isReady
.
To make my code more reusable, I decided to create a function called
changeMapStatus(state, key, value)
to handle this task.
This function is meant to update the property state.map.status.key
with the value it receives.
However, when I try to call the mutation using
this.$store.commit('changeMapStatus', 'isReady', true)
from a component file, it somehow removes the existing state.map.status.isReady
and sets it to undefined
.
On the other hand, if I modify the function to look like this:
changeMapStatus(state, value) {
state.map.status.isReady = value;
}
it seems to work fine.
Can someone point out where I might be going wrong?
Thank you in advance!
store.js (Vuex)
import Vue from 'vue';
import Vuex from 'vuex';
Vue.use(Vuex);
export default new Vuex.Store({
state: {
map: {
status: {
isReady: false,
},
},
},
mutations: {
changeMapStatus(state, key, value) {
state.map.status[key] = value;
}
},
});