I am facing an issue where I have two objects that contain the same data. I need to remove an item from one of the objects without affecting the other. However, when I try to use the splice method on one object, it also affects the other one and I end up losing the item in both objects.
<button @click="deleteData(0)" />
export default {
data() {
return {
arrayA: [],
arrayB: []
}
},
methods: {
async initData() {
const { data: response } = await this.$store.dispatch("getData", { id: this.$route.params.id })
this.arrayA = response
this.arrayB = response
},
deleteData(indexOfItem) {
console.log("arrayA & arrayB before splice: ", this.arrayA, this.arrayB);
// arrayA & arrayB before splice : [{...}, {...}], [{...}, {...}]
this.arrayA.splice(indexOfItem, 1);
console.log("arrayA & arrayB after splice :", this.arrayA, this.arrayB);
// arrayA & arrayB after splice : [{...}], [{...}]
}
}
}