Level 39
It doesn't appear that you've mapped your state. You reference getItem on this.localStorage, but you haven't defined this.localStorage.
Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.
Please help, since I moved my VUEX stores into seperate modules, I now get the following error when trying to login:
Cannot read property 'getItem' of undefined here is my page:
import { mapGetters } from 'vuex'
export default {
middleware: 'auth',
data() {
return {
username: null,
token: this.localStorage.getItem('auth._token.local')
}
},
mounted() {
console.log('here:', this.localStorage.getItem('auth._token.local'))
this.showUser()
},
methods: {
async showUser() {
await this.$axios.get('user', {
headers: {
Authorization: `${this.token}`
}
}).then((res) => {
this.username = res.data.name
})
}
},
computed: {
...mapGetters(['loggedInUser'])
}
}
Thanks
Please or to participate in this conversation.