Currently delving into the world of VueJS.
I have a Method that is designed to take in an Object as its parameter.
In order to avoid modifying the original Object, I make use of Object.assign()
to create a clone of it.
Component.vue
export default {
// ...
methods: {
// ...
activateEditMode (item) {
this.editItemIndex = this.travelItinerary.indexOf(item)
this.editItem = Object.assign({}, item)
// ...
}
}
}
The initial Object at this.roteiroCompleto[0]
:
https://i.sstatic.net/7md2U.png
However, when I edit the cloned Object labeled as this.itemEditado
:
https://i.sstatic.net/i9TP3.png
the changes also reflect on the original Object this.roteiroCompleto[0]
.
https://i.sstatic.net/H1sHB.png
I've attempted various methods to prevent this binding issue, such as copying each key and value individually, using .slice()
, .map(a=>a)
, yet nothing seems to work. The connection between the two objects remains intact.
Upon executing console.log(this.itemEditado)
, the following output is generated:
https://i.sstatic.net/DHBbl.png
Interestingly, in another Vue Component utilizing the same approach, everything operates as intended.