I am trying to validate my user in navbar but it return
[Vue warn]: Error in render: "TypeError: Cannot read property 'type' of undefined"
App.vue (main component for routes)
<router-view id="content" :user="user" :currency="currency" :key="$route.fullPath"></router-view>
///////
methods: {
currency() {
this.$store.dispatch('currency')
},
user() {
this.$store.dispatch('user')
},
}
store.js
state: {
user: {},
currency: {}
},
mutations: {
currency(state, currency){
state.currency = currency
},
user(state, user){
state.user = user
}
},
actions: {
user({commit}){
return new Promise((resolve, reject) => {
commit('user')
axios.get('/api/auth/user', {
headers: {
Authorization: 'Bearer ' + localStorage.getItem('access_token')
}
})
.then(resp => {
const user = resp.data
commit('user', user)
resolve(resp)
})
.catch(err => {
commit('user')
reject(err)
})
})
},
getters: {
isLoggedIn: state => !!state.token,
loggedUser: state => state.user,
currency: state => state.currency,
}
navBar.vue
<li v-if="isLoggedIn && this.$store.getters.loggedUser.type == 'admin'" class="nav-item dropdown">
...
</li>
///////
export default {
props:['currency', 'user'],
name: 'navbar',
data() {
return {
userPhoto: '',
site_name: process.env.MIX_APP_NAME
}
},
computed : {
isLoggedIn() {
return this.$store.getters.isLoggedIn
}
},
}
Now even in navbar itself if i do {{this.$store.getters.loggedUser.type}} it print what i'm looking for but since it's in that <li> it returns error.
Any idea?
thisin the template. So just$store.getters...userand confirm if the response actually returns the right data?$store.getters.loggedUser.type == 'adminis true, yet i'm getting error