Answer the question
In order to leave comments, you need to log in
LocalStorage is not defined?
I use the nuxt js framework, when using the localstorage object, it gives out undefined ... I read why this happens, they say that you need to set the proccess.client flag so that .. it works on the client but without the original
getItem (KEY, defaultValue = null) {
const value = JSON.parse(localStorage.getItem(KEY))
if (!value) {
return defaultValue
}
return value
},
Answer the question
In order to leave comments, you need to log in
process.client is just a check for the rendering type, not a guarantee of the client one :)
It's not clear in your code where exactly the getItem method is called.
Based on this, I can only say one thing - pull it in the mounted hook, in which the window object is definitely available (localStorage is its property)
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question