Search code examples
vue.jsvuexnuxt.jsvuex-modules

How to call a getter inside a computed properties


I am using the modules mode of the store and in my projects.js inside my store folder I have:

export const getters = {
   loadedProjects(state) {
       return state.loadedProjects;
   }
}

now in my computed how should I call it? I’m trying like that:

computed: {
   loadedProjects() {
     return this.$store.getters.projects.loadedProjects;
   },
 }

but I get this error:

Cannot read property ‘loadedProjects’ of undefined

Solution

  • I had the same problem, if you are using the modules mode you can call your getters like that (in your case): this.$store.getters['projects/loadedProjects'];

    So try to change your computed like that:

    computed: {
       loadedProjects() {
         return this.$store.getters['projects/loadedProjects'];
       },
     }