I get an error with my App.vue component , getter: logged
<li id="shoppinglists" v-if="!logged">...
ERROR LOG: '[Vue warn]: Property or method "logged" is not defined on the instance but referenced during render.
Make sure that this property is reactive, either in the data option, or for class-based components, by initializing the property.
I don't understand why it's stated as non-defined, as I don't get error with another defined getter: currentUserId
<li v-else id="shoppinglists"><router-link :to="{ name: 'ShoppingLists', params: { id: currentUserId } }" >Shopping Lists</router-link></li>
Bothe are defined as computed props :
<script>
import store from '@/vuex/store'
import { mapGetters } from 'vuex'
export default {
name: 'app',
computed: {
...mapGetters([
{ currentUserId: 'getCurrentUserId' },
{ logged: 'getCurrentUserStatus' }
])
},
store
}
</script>
and my vex/getters.js is :
vuex/getters.js
export default {
getCurrentUserStatus: state => state.logged,
getCurrentUserId: state => state.currentUserId,
...
}
and my store is
vuex/store.js
import Vue from 'vue'
import Vuex from 'vuex'
import getters from './getters'
...
Vue.use(Vuex)
const state = {
logged: false,
currentUserId: '',
...
}
export default new Vuex.Store({
state,
getters,
...
})
Just pass an object to ...mapGetters
if you want to use the getters with different name
So the syntax is:
...mapGetters({
currentUserId: 'getCurrentUserId',
logged: 'getCurrentUserStatus'
})