Skip to content Skip to sidebar Skip to footer

How To Commit Mutations In A Vuex Store, From A Vuetify List, VueJS

This follows on from my previous question : How to get states from a Vuex store from within a Vuetify list, VueJs I understand how to get states from the store, but I am struggling

Solution 1:

Why do you want to store a function to commit a mutation in the data option?You can just store the information needed to commit a mutation.

export default{
    name: 'menuList',
    data() {
        return {
            show: true,
            items: [{
                    title: 'Do something',
                    icon: 'web',
                    mutation: {
                        type: 'UI/DoSomething',
                         arguments:{ 
                            argument1: "argument1",
                            rootStore: this.$store
                        }
                        }
                    }

                }
            ]
        }
    }
} 

Then create a method as follows

commitMutation(mutation) {
     this.$store.commit(mutation.type, mutation.arguments)

}

Then add a click listener with item.mutation as an argument to commitMutation method.

@click="commitMutation(itrm.mutation)"

Post a Comment for "How To Commit Mutations In A Vuex Store, From A Vuetify List, VueJS"