Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

102
Visualizações
vue-persistedstate reducer with path

im using vue-persistedstate with specific modules to be set persisted only, and it's working well using path attribute.

but when i try to mix it with reducer, the modules set in the path is not working anymore and reducer set all modules persisted. how should i do with reducer?

const persistedstate = new createPersistedState({
  key: "newsportal-vuex",
  storage: window.localStorage, 
  paths: ["auth", "venues", "play", "playWS", "purchaseSettings"], // only the persisted ones
  reducer(val) {
    if (!localStorage.getItem("newsportal_isuseracceptcookie")) {
      // DONT USE PERSISTEDSTATE IF USER DECLINE COOKIES
      return {};
    }
    return val; // <-this return ALL MODULES. i want to set only modules in path
  }
});

thanks in advance

about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

just realised i need to rebuild the object

reducer(val, paths) {
    if (!localStorage.getItem("newsportal_isuseracceptcookie")) {
      // DONT USE PERSISTEDSTATE IF USER DECLINE COOKIES
      return {};
    }

    // make persisted state as in paths
    let reducer = {};

    Object.entries(val).forEach(entry => {
      const [key, value] = entry;
      if (paths.includes(key)) {
        reducer[key] = value;
      }
    });

    return reducer;
  }

about 4 years ago · Juan Pablo Isaza Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda