{"action":"created","issue":{"url":"https://api.github.com/repos/vuejs/vue/issues/2037","labels_url":"https://api.github.com/repos/vuejs/vue/issues/2037/labels{/name}","comments_url":"https://api.github.com/repos/vuejs/vue/issues/2037/comments","events_url":"https://api.github.com/repos/vuejs/vue/issues/2037/events","html_url":"https://github.com/vuejs/vue/issues/2037","id":122589809,"number":2037,"title":"How to use localStorage with vue?","user":{"login":"seemsindie","id":1268576,"avatar_url":"https://avatars.githubusercontent.com/u/1268576?v=3","gravatar_id":"","url":"https://api.github.com/users/seemsindie","html_url":"https://github.com/seemsindie","followers_url":"https://api.github.com/users/seemsindie/followers","following_url":"https://api.github.com/users/seemsindie/following{/other_user}","gists_url":"https://api.github.com/users/seemsindie/gists{/gist_id}","starred_url":"https://api.github.com/users/seemsindie/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/seemsindie/subscriptions","organizations_url":"https://api.github.com/users/seemsindie/orgs","repos_url":"https://api.github.com/users/seemsindie/repos","events_url":"https://api.github.com/users/seemsindie/events{/privacy}","received_events_url":"https://api.github.com/users/seemsindie/received_events","type":"User","site_admin":false},"labels":[],"state":"closed","locked":false,"assignee":null,"milestone":null,"comments":1,"created_at":"2015-12-16T20:02:20Z","updated_at":"2015-12-16T20:30:37Z","closed_at":"2015-12-16T20:30:36Z","body":"I posted on chat(twice), nobody answered, so i am hoping i can get some help here.\r\n\r\nI have a mixin isLoggedIn() that return true if item is present in localStorage and false if it isn't.\r\nMy question is, how can i re-evaluate the state when i update or remove item form localStorage, because i have some elements shown only if isLoggedIn is true?\r\n\r\nAnd is it right to use v-show=\"isLoggedIn()\" or would you suggest something else, i don't know what is the best practice for this?\r\n\r\nThanks guys."},"comment":{"url":"https://api.github.com/repos/vuejs/vue/issues/comments/165235899","html_url":"https://github.com/vuejs/vue/issues/2037#issuecomment-165235899","issue_url":"https://api.github.com/repos/vuejs/vue/issues/2037","id":165235899,"user":{"login":"yyx990803","id":499550,"avatar_url":"https://avatars.githubusercontent.com/u/499550?v=3","gravatar_id":"","url":"https://api.github.com/users/yyx990803","html_url":"https://github.com/yyx990803","followers_url":"https://api.github.com/users/yyx990803/followers","following_url":"https://api.github.com/users/yyx990803/following{/other_user}","gists_url":"https://api.github.com/users/yyx990803/gists{/gist_id}","starred_url":"https://api.github.com/users/yyx990803/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/yyx990803/subscriptions","organizations_url":"https://api.github.com/users/yyx990803/orgs","repos_url":"https://api.github.com/users/yyx990803/repos","events_url":"https://api.github.com/users/yyx990803/events{/privacy}","received_events_url":"https://api.github.com/users/yyx990803/received_events","type":"User","site_admin":false},"created_at":"2015-12-16T20:30:36Z","updated_at":"2015-12-16T20:30:36Z","body":"The catch here is that localStorage is not reactive, so you need something that **is** reactive to trigger the changes. Basically, you use an object to represent the login state, and when you login/logout, you'd modify localStorage and that object together (and initialize that object by reading from localStorage on app load).\r\n\r\nSee http://vuejs.org/guide/application.html#State_Management\r\nand https://auth0.com/blog/2015/11/13/build-an-app-with-vuejs/ which does exactly what you are trying to do."}}