[Vuejs]-Can't access object properties even though I can see they exist

3๐Ÿ‘

โœ…

When I just do console.log(JSON.parse(this.$store.state.user)); I get the object and I can see the properties.

This means that this.$store.state.user contains JSON string which describes the user object.

Thus JSON.parse(this.$store.state.user.userId) is incorrect. In this case you are trying to get property userId from string, getting undefined and JSON.parse function fails on the first symbol, which is 'u'.

You should use JSON.parse(this.$store.state.user).userId instead.

๐Ÿ‘คSergey Mell

Leave a comment