I was follow the answer below to work with add row dynamically. This is the link
Everything is alright until I wanted to remove row dynamically. I used splice to remove row but my issue is that the images that I have selected to each row is messed up after I remove the selected row.
The images below can spot the different.
So, as you can see the image that I selected for these rows are 1, 2 and 3.
Now I remove the second row which has image name 2.
My expected result is that the file should be 3 as I removed the 2nd row. The 2nd row is removed but the image label is remain the same.
This is my code.
<div
class="row"
style="margin-bottom: 10px;"
v-for="(item, index) in form.rowData"
:key="index"
>
<div class="col-md-3">
<div class="form-group">
<label for="inputSelect" class="col-lg-3">Amount</label>
<div class="col-lg-8">
<div class="bs-component">
<input
v-model="form.rowData[index].amount"
type="number"
step="0.01"
id="inputStandard"
class="form-control"
/>
</div>
</div>
</div>
</div>
<div class="col-md-4">
<div class="form-group">
<label for="inputSelect" class="col-lg-3">Image</label>
<div class="col-lg-8">
<div>
<input
v-if="uploadReady"
type="file"
:name="index"
accept="image/*"
@change="onFileChange"
/>
</div>
</div>
</div>
</div>
<div class="col-md-1">
<div v-if="index == form.rowData.length -1">
<a @click="addItem">
<span style="font-size:30px;" class="fa fa-plus-circle" />
</a>
</div>
<div v-else>
<a @click="removeItem(index)">
<span style="font-size:30px; color: red;" class="fa fa-times-circle" />
</a>
</div>
</div>
</div>
methods: {
addItem() {
var my_object = {
amount: "",
image: ""
};
this.form.rowData.push(my_object);
},
removeItem(index) {
this.form.rowData.splice(index, 1);
},
}
Is anyone can help with this issue? Im using vueJs and used splice to remove the element in rowData.