I have two button called ADD and REMOVE LAST ROW. If I click on ADD it will add new input field and if I click on REMOVE LAST FIELD it will delete the last row. When we click ADD it will display input field with a button called REMOVE THIS ROW, is there a way to make that button REMOVE THIS ROW delete the particular field or row?
Like if I pressed ADD button three times 1,2 and 3. Then if I click on REMOVE THIS ROW button for second one, then remove the second one.
View
<div id="app">
<div class="work-experiences">
<div class="form-row" v-for="(minordatabase, index) in minorsDetail" :key="index">
<div class="col">
<br>
<label id="minorHeading">FULL NAME</label>
<input v-model="minordatabase.full_name" type="text" class="form-control" placeholder="FULL NAME" size="lg"/>
<button type="button" class="btn btn-outline-info">Remove this row</button>
</div>
</div>
</div>
<br>
<div class="form-group">
<button @click="addExperience" type="button" class="btn btn-info" style="margin-right:1.5%;">Add</button>
<button @click="removeExperience" type="button" class="btn btn-outline-info">Remove Last Field</button>
</div>
</div>
Script
new Vue({
el: "#app",
data: {
minorsDetail: [
{
full_name: "",
date_of_birth: "",
}
],
},
methods: {
toggle: function(todo){
todo.done = !todo.done
},
addExperience(){
this.minorsDetail.push({
full_name: ''
})
},
removeExperience: function(todo){
var index = this.minorsDetail.indexOf(todo)
this.minorsDetail.splice(index, 1)
this.removeMinorFieldFunction();
},
}
})
Below is the code on JsFiddle