0

in my Vue Js project i wanted to check if user logged in so he can access website and if not it should take him to /login page.. since i'm new to Vue Js i tried the below code but it didn't work in app.js, can someone please help me in this ?

  mounted: function(){
       if(JSON.parse(sessionStorage.user)){
          console.log(JSON.parse(sessionStorage.user))
        }
    }

0

1 Answer 1

1

You need to get the value from sessionStorage. Something like this would work

sessionStorage.getItem('name of the key')
Sign up to request clarification or add additional context in comments.

2 Comments

what do you mean by the name of the key ididn't really get it?
By name of the key I meant by what name it is getting stored in the session storage. Data is always stored in key/value pair in web storage.

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.