I have the following Navigation.vue
component:
<template>
<div>
{{user.first_name}}
</div>
</template>
<script>
import { mapActions, mapGetters } from 'vuex'
export default {
name: 'hello',
methods: {
...mapActions(['myAccount'])
},
mounted: function () {
if (localStorage.getItem('access_token')) {
this.myAccount()
}
},
computed: {
...mapGetters(['user'])
}
}
</script>
This code returns:
[Vue warn]: Error in render function: "TypeError: Cannot read property 'first_name' of null"
but the strange thing is that user first name is showing correctly. What am I doing wrong?
user
is initialized asnull
. Just initialize theuser
to an empty object{}
. – Respecting