As you know, nuxtjs is server side rendering and there is no good example how to store data into localstorage which is client side.
My work is need to build login form w
You can use process.browser
to check it's in browser or not.
export default {
created() {
this.storeToken();
},
methods:{
storeToken(token){
if(process.browser){
localStorage.setItem("authToken", token);
}
}
}
}
You also call this method in mounted without check process.browser
.
export default {
mounted() {
this.storeToken();
},
methods:{
storeToken(token){
localStorage.setItem("authToken", token);
}
}
}