I am moving from classic vuex to modular vuex, but i need some help understanding how to call getters in my app. Here's what I have in store:
store/user.js:
export const state = () => ({
currentUser: null,
userProfile: {}
})
export const getters = {
loggedIn(state) {
return !!state.currentUser
}
}
When I call loggedIn from my app, I get loggedIn as undefined. Here's how I am calling loggedIn:
src/components/MainNav.vue:
computed: {
loggedIn() {
return this.$store.getters.user.loggedIn
}
}
Anyone spot what I am doing wrong? Thank you!
Your store has the
usernamespace, so you have to call yourloggedIngetter as below:Another way is to use the
mapGetterhelper, as explains in Vuex docs