I have implemented a function on my form that allows me to add multiple file inputs for various images by clicking a button. Although this functionality is working correctly, I am facing an issue while trying to delete an input field using .splice. Instead of deleting the input field with the matching index, it keeps removing the last item in the array where my input fields are stored. Despite spending hours attempting to resolve this problem, I am unable to find a solution. I would greatly appreciate any help or advice on what might be causing this error.
Here is the method used to add a new input field:
addInputField() {
i++
this.values.links.push({
id: i,
url: ''
});
}
This is the code snippet responsible for deleting an input field:
deleteInputField(index) {
this.values.links.splice(index, 1);
const items = this.values.links.filter(item => {
return item.id > index
});
items.forEach(function (item) {
item.id = item.id -1;
});
}
Below is the button used to delete the input field:
<v-icon
medium
v-if="link.id > 0"
color="#FF0000"
class="ma-4"
@click="deleteInputField(link.id)"
>