I have the following data:
data: {
usuario: {
nombres: 'name',
email: 'cor',
telefono: 'tel',
fechan: '2018-10-15',
rol : 3,
idTarget: 0
},
listaUsuarios:{
0:{
idTarget: 0,
nombres: 'name',
telefono: 'telefono',
estado: 0,
rol : 3,
email : '',
fechan: ''
}
}
},
I have a method in which the user assigned listausuarios[index]
, however when I edit inputs
whose v-model
are user, ALSO change listausuarios[index]
is as if they were intertwined.
openmodalEditUser: function(idUser, index){
this.pivotAction = true;
this.usuario = this.listaUsuarios[index];
}
<div class="modal-header">
<h5 class="modal-title" id="exampleModalLabel">Registrar un nuevo usuario.</h5>
<button type="button" class="close" data-dismiss="modal" aria-label="Close">
<span aria-hidden="true">×</span>
</button>
</div>
<div class="modal-body">
<div class="row">
<div class="col-md-12">
<div class="md-input">
<input class="md-form-control" required="" v-model="usuario.nombres" type="text">
<span class="highlight"></span>
<span class="bar"></span>
<label>Nombre:</label>
</div>
</div>
<div class="col-md-12"><br></div>
<div class="col-md-12">
<div class="md-input">
<input class="md-form-control" required="" v-model="usuario.email" type="text">
<span class="highlight"></span>
<span class="bar"></span>
<label>Correo:</label>
</div>
</div>
<div class="col-md-12"><br></div>
<div class="col-md-12">
<div class="md-input">
<input class="md-form-control" required="" v-model="usuario.telefono" type="text">
<span class="highlight"></span>
<span class="bar"></span>
<label>Teléfono:</label>
</div>
</div>
<div class="col-md-12"><br></div>
<div class="col-md-12">
<div class="md-input">
<input class="md-form-control" required="" v-model="usuario.fechan" type="date">
<span class="highlight"></span>
<span class="bar"></span>
<label class="labels-no-anim">Fecha Nacimiento:</label>
</div>
</div>
I just want that when you run this method users I take the user from the list that I say, but not the reverse or both directions. and even more, understand why this happens.
That is, the problem is that when doing
this.usuario = this.listaUsuarios[index];
If I change this.usuario
, listaUsuarios[index]
is also modified