1

I'm using a Vuex store to store a user object. This is a getter for the user object

getters: {
    user: (state) => state,
    isAuthenticated: state => {
      console.log("user object", state);
      console.log("authorized", state.authorized);
      return state.authorized;
    }
},

However, when calling the getter this is what gets logged to the console.

enter image description here

As you can see the value for authorized changes whether the entire object is called or just the value itself. Any ideas?

1 Answer 1

2

It's probably because the console evaluates the object only when you expand it, and by that time authorized has been set to true. When logging objects, you aren't seeing a snapshot of the object at the moment it was logged.

In Chrome dev tools, hovering over the i symbol displays this tooltip:

Screenshot

Firefox dev tools does a similar thing.

It's best to set a breakpoint and inspect the object state in the debugger.

Sign up to request clarification or add additional context in comments.

2 Comments

I think breakpoint is not even needed here if one is using Vue Dev Tools. Just clicking on different commits would display what has been changed :)
@GytisTG But that doesn't help in this situation where OP wants to inspect the state at the execution of a specific line of code.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.