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

80
Vistas
Changed object path and Dirty stages for nested objects in Vue state

Let's say I have an object contains some array of objects in some of its properties. Whenever I make changes in some fields whether it's a field in object in array or the root object, I want to define that object "dirty: true" with a code like this: object.defineProperty(path, '_dirty', true).

{
    "id": "48e143e5-eda0-490a-a87a-dbef128f539e",
    "parentId": null,
    "groups": [
        {
            "id": "142c7263-26ab-4169-88bb-5b2b880f3b97",
            "overviewId": "48e143e5-eda0-490a-a87a-dbef128f539e",
            "parts": [
                {
                    "id": "730adbca-20c0-427a-8228-7000d0553466",
                    "overviewGroupId": "142c7263-26ab-4169-88bb-5b2b880f3b97",
                },
                {
                    "id": "9c749aa0-b1c0-49cd-81c1-272d9bfe5df7",
                    "overviewGroupId": "142c7263-26ab-4169-88bb-5b2b880f3b97",
                }
            ],
        }
    ],
    "templateInfo": {
        "id": "34d2be1c-9b4e-4eb2-b452-82c7929057c8",
        "name": "Standart OV",
        "parentId": null,
        "typeId": 0,
        "storeId": "ee7bdc31-8c13-4111-9225-cb780b46e1a1"
    },
    "pageTypeInfo": {
        "id": "016ef17a-4cd7-4096-b387-6b16c39df41e",
        "typeId": 3,
        "code": "code A",
    }
}

I am storing this object in data like this:

data() {
    return {
        source: {},
    }
},

and have a watcher:

source: {
    handler(newValue, oldValue){
        console.log(...arguments)
    },
    deep: true
}

Is it possible to have the changed path like "groups[0].parts[1].id" and make the _dirty true for targeted object which in the path when change occurs?

about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

You can create a method that updates the value using the $set function like so:

update(root, key, value) {
  this.$set(root, key, value);
  this.$set(root[key], '__dirty', true); 
}
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