murilo's avatar
Level 10

Vuex , how make a betther code

Hello Guys , I wold like to know if has any way to re use codes , or expand a class inside VUEX . I know that in VUE we have mixins , but I dont know if that it is possible to use in VUEX . I have many VUEX CRUD modules . and in all those modules I have those actions ( they are the same )-

 set_filters: ({commit}) => {
  } ,
store: ({commit} , data ) => {
}
update: ({commit} , data ) => {
}
delete: ({commit} , data ) => {
}
pagination: ({commit} , data ) => {
}
search: ({commit} , data ) => {
}

What wold be the best practice to I dont repeat all those code in all those VUEX modules ?

0 likes
2 replies
murilo's avatar
Level 10

I wold like to implement a class inside the VUEX , I dont know if that is possible . or something like that in my VUEX MUDULES -

import CrudMuttation from "../cruds/mutation";
import CrudActions from "../cruds/actions";
import CrudGetters from "../cruds/getters";
import CrudGetters from "../cruds/getters";

const state = { 
    pageProperty : { title:'' , product:'' }  ,
        searchProperty: { title:'' }  
}

const mutations = {
    CrudMuttation 
}

const actions= {
    CrudMuttation 
}

const getters= {
    CrudGetters 
}


export default {
    namespaced:true ,
    state,
    mutations,
    actions,
    getters
}

can I do something like that ?

Please or to participate in this conversation.