Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

144
Vistas
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 Respuestas
Responde la pregunta

0

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

about 4 years ago · Juan Pablo Isaza Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda