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

140
Visualizações
Value retrived by vue-cookie won't trigger lifecycle method "updated"

I'm trying to save and read multiple json objects from my vue-application with the vue-cookie package (Version 1.1.4). The snippet below runs really well and the json object is saved and retrivied as expected.

However, I noticed as soon as the data is retrieved via cookies and i want to change data inside the object on the web page, the "updated" lifecycle method will not trigger. This behaviour is really awkward as I am only adding the cookieToJson() method to the beforMount() method. The Vue debugger also shows that the value is changed. I think the data is not reactive anymore, but how can I fix this.

data () {
   return {
      json: {
         a: 0,
         b: 1,
      },
   }
},
methods: {
   jsonToCookie(name) {
      const data = "{\"" + name + "\": " + JSON.stringify(this[name])+"}";
      this.$cookie.set(name, data, { expires: '1M' }, '/app');
   },
   cookieToJson(name) {
     const data = JSON.parse(this.$cookie.get(name));
     if(data==null) return
     for(var i = 0; i < Object.keys(data).length; i++) {
       var name = Object.keys(data)[i]
       this[name] = data[name];
     }
   },
   beforeMount() {
     console.log("beforeMount")
     this.cookieToJson("json")
   },
   updated() {
     console.log("updated")
     this.jsonToCookie("json")
   },
}
about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

In case anyone run into a similar problem, I am using the localStorage now.

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