How to store data to local storage with Nuxt.js

前端 未结 3 2013
忘了有多久
忘了有多久 2021-02-15 15:02

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

3条回答
  •  孤街浪徒
    2021-02-15 15:29

    nuxtjs provides you with process.browser to tell it to execute only on the client side

    so use it like this:

    methods:{
        storeToken(token){
            if(process.browser){
                localStorage.setItem("authToken", token);
            }
        }
    }
    

    see this link for more info

提交回复
热议问题