2

In order to make a simple vuex store we have created a generic mutation & action which would store any type of object we would like to pass when calling the action.

A lot of the examples I have seen online have a mutation for each property being updated, does this mean that using generic mutations is bad practice? Is there a better way to do this?

Here is our vuex store:

const store = new Vuex.Store({
    state: {
        user: User,
        signedIn: Boolean
    },
    mutations: {
        updateProp (state: any, payload: any){
            state[payload.prop] = payload.value;
        }
    },
    actions: {
        async updateProp(context, payload: any){
            await context.commit("updateProp", payload);
        }
    }
})
DrollDread
  • 321
  • 4
  • 22

0 Answers0