3

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,
   ...
})

1 Answer 1

1

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' 
 })
Sign up to request clarification or add additional context in comments.

1 Comment

thanks a lot .. I did not get it right in writing it... I thought it was an array of objects... now I an see the vex binding in my Vue tool... !

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.