我有以下Navigation.vue
个组件:
<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>
此代码返回:
[Vue warn]: Error in render function: "TypeError: Cannot read property 'first_name' of null"
但奇怪的是,用户名显示正确.我做错了什么?