[Vuejs]-How can I change Vuex store obejct value with actions?(vue.js)

0👍

You need to know beforehand the id and also the value of the new array. To find and change the desired object in the state array, you can use the mutation in the example below:

const store = new Vuex.Store({
  state: {
    objects: [{ id: 1, value: true }, { id: 2, value: true }]    
  },
  mutations: {
    changeObjectValue (state, { id, value }) {
        const found = state.objects.find(item => item.id === id);
        found.value = value;               
    },
  },
});

This way you can commit inside one action like this:

store.commit('changeObjectValue', {id: 2, value: false});

Check this example on plnkr

Leave a comment