niksolaz
niksolaz

Reputation: 102

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

Upvotes: 1

Views: 925

Answers (2)

Luca Spezzano
Luca Spezzano

Reputation: 380

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'];
   },
 }

Upvotes: 2

niclas_4
niclas_4

Reputation: 3674

You have to call your getter like this:

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

$store.getters['moduleName/getterName']

Upvotes: 1

Related Questions