你的问题是这个
this.sections[index].additionals[indexSection].splice(indexSection,1)
把它改成
this.sections[index].additionals.splice(indexSection,1)
它工作得很好
var app = new Vue({
el: '.container',
data: {
sections: [{
item: '',
additionals: [] // <-
}]
},
methods: {
addNewSection() {
this.sections.push({
item: '',
additionals: [] // <-
})
},
addNewItem(index) {
this.sections[index].additionals.push({
item: ''
})
},
deleteSection(index) {
this.sections.splice(index, 1)
},
deleteAdditional(index, indexSection) {
console.log(index, indexSection)
//this.sections[index].additionals.splice(index,1)
this.sections[index].additionals.splice(indexSection, 1)
}
}
})
<script src="https://cdn.jsdelivr.net/vue/latest/vue.js"></script>
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" integrity="sha384-BVYiiSIFeK1dGmJRAkycuHAHRg32OmUcww7on3RYdg4Va+PmSTsz/K68vbdEjh4u" crossorigin="anonymous">
<div id="app">
<div class="container">
<button class="btn btn-success mt-5 mb-5" @click="addNewSection">
New Deal Section
</button>
<div class="card mb-3" v-for="(section, index) in sections">
<hr>
<div class="card-body">
<button class="btn btn-success mt-5 mb-5" @click="addNewItem(index)"> <!-- passing the index -->
New Item
</button>
<span class="float-right" style="cursor:pointer" @click="deleteSection(index)">
X
</span>
<h4 class="card-title">Deal section {{ index + 1}}</h4>
<div class="employee-form">
<input type="text" class="form-control mb-2" placeholder="Item" v-model="section.item">
</div>
<div class="employee-form" v-for="(addition, indexSection) in section.additionals">
<!-- additionals of the section -->
<input type="text" class="form-control mb-2" placeholder="Addition" v-model="addition.item">
<span class="float-right" style="cursor:pointer" @click="deleteAdditional(index,indexSection)">
X
</span>
</div>
</div>
</div>
</div>
</div>