[Vuejs]-How do I initialise state in Nuxt.js which includes localStorage while Universal Rendering

0👍

you can use typeof window === 'undefined' to determine if it running in Server Side, and skip the code you only want to run in client, just like:

if (typeof window !== 'undefined') {
   // your code
}

You can use it in created/beforeCreate/asyncData , And if you code is in mounted(), you may not need do this, ‘case this Lifecycle Hooks only run in the client.

0👍

You can write a Middleware and dispatch your action that checks the token in it and call it in the layout.
https://nuxtjs.org/docs/2.x/directory-structure/middleware

Leave a comment