Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

281
Views
How persisted specific data in localStorage in Nuxt.js?

All the data present in my store is persisted in the localStorage but I would like to persist only my user, the user is stored in a nuxt.js store.

Here is my store/login.js

export const state = () => ({
    user: ''
})

export const mutations = {
    setUser(state, newUser) {
        state.user = newUser;
    }
}

export const getters = {
    getUser(state) {
        return state.user
    }
}

And I am using vuex-persist plugin to persist the data. Here is my plugin/vuex-persist :

import VuexPersistence from 'vuex-persist';

export default ({ store }) => {
  new VuexPersistence({
    key: 'vuex',
    storage: window.localStorage,
  }).plugin(store);
}

Thanks for your help !

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

From the vuex-persist documentation:

const vuexCookie = new VuexPersistence<State, Payload>({
  restoreState: (key, storage) => Cookies.getJSON(key),
  saveState: (key, state, storage) =>
    Cookies.set(key, state, {
      expires: 3
    }),
  modules: ['user'], //only save user module
  filter: (mutation) => mutation.type == 'logIn' || mutation.type == 'logOut'
})

The options object has a "modules" key that expects a string[] value, with the names of the modules you DO want to serialize.

Constructor param: modules
Value type: string[]
Description: List of modules you want to persist. (Do not write your own reducer if you want to use this)
about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!