Reputation: 401
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))
}
}
Upvotes: 0
Views: 794
Reputation: 26
You need to get the value from sessionStorage. Something like this would work
sessionStorage.getItem('name of the key')
Upvotes: 1