I am having some odd behaviour on my component. I have a list of buttons and when clicked each is supposed to be removed from the DOM by removing it from the array. In this case I am using the function removeItem
and passing it the index of the item. That works fine and it is being removed from the array abc[]
but what is unexpected is that the same item is being removed from another array xxzz[]
<template>
<button v-for="(item, index) in abc" @click="removeItem(index)">{{ item.name }}</button>
</template
export default {
data: () => ({
abc: [],
xxzz: [],
}),
methods: {
removeItem(index){
this.abc.splice(index, 1);
},
},
created(){
var vm = this;
let formData = new FormData();
axios({
url: '/get/items',
method: 'post',
data: formData
})
.then(function (response) {
if(response.status == 200){
vm.abc = response.data.items;
vm.xxzz = response.data.items;
}
});
}
}