I am using vuejs to create a form that stores data in an array. My problem is that when making a change, it is reflected in the "copies" that exist. I would like to know if there is any way to remove this characteristic of vuejs from being reactive, but only in a specific element. For example if I have my array defined in the data:
miArreglo =[]
otroArreglo = []
Then in a function I do the following:
funcionCualquiera () {
this.otroArreglo = miArreglo.push()
}
If at some point I deleted what is in miArreglo
, the "copy" saved in otroArreglo
. Is there any way to avoid this?
No, you don't want to remove reactivity from VUE. NEVER . What you want to do, is that those two arrays are copies of each other, at least initially, but not the same array.
when doing
You are telling it that otherArray is the same array as myArray, because what is stored in those variables is the reference to the array, and not its content.
if you want to copy myArray to anotherArray, what you have to do is
That what it is going to do is copy the content of an array into another array, and they are going to be different arrays.
NOTE
myArray.push() actually returns the length of the new array, so I guess that was a bug copying your code.