I\'m attempting to watch for localstorage:
Template:
token - {{token}}
Script:
computed: {
t
The VueJs site has a page about this. https://vuejs.org/v2/cookbook/client-side-storage.html
They provide an example. Given this html template
My name is
They provide this use of the lifecycle mounted method and a watcher.
const app = new Vue({
el: '#app',
data: {
name: ''
},
mounted() {
if (localStorage.name) {
this.name = localStorage.name;
}
},
watch: {
name(newName) {
localStorage.name = newName;
}
}
});
The mounted method assures you the name is set from local storage if it already exists, and the watcher allows your component to react whenever the name in local storage is modified. This works fine for when data in local storage is added or changed, but Vue will not react if someone wipes their local storage manually.