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

169
Vistas
Passing data to child component also changes parent data

Passing data from parent to child is a piece of cake and never had a problem that when you update the child prop data also updates the parent data at the same time, although now i want to avoid that.

I have this child component inside the parent component

    <address-dialog v-if="dialog.address.status" :countries="countries" :address-data="dialog.address.data" 
:open="dialog.address.status" @close="dialog.address.status = !dialog.address.status"></address-dialog>

Inside the child component i pass the props as is and then set them with the data method.

props: {
    open: {
        type: Boolean,
        default: false
    },
    addressData: {
        type: Object,
        default: null
    },
    countries: {
        type: Array,
        default: null
    }
},

data() {
    return {
        mdiClose,
        loading: false,
        valid: false,
        dialog: this.open,
        address: this.addressData,
        cities: [],
        states: [],
        overlay: false,
        snackbar: {
            status: false, 
            text: '',
            color: '#FF5252'
        },
        rules: {
            required: value => !!value || 'Required.',
        },
    }
},

When updating address inside the child component it also automatically updates the address in the parent component, how can i avoid that?

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

0

Because they have the same reference ( as the address is an object ).

One solution is to pass a new object that has the addressData properties by spread operator.

address: { ...this.addressData }
about 4 years ago · Juan Pablo Isaza Denunciar

0

You should define the data properties bound to props as computed ones :

computed:{
   address(){
     return  this.addressData
   },
   dialog(){
    return this.open;
   }
}
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