我做错了什么? 我正在尝试使用删除按钮删除一个人的数据。
<li v-for="(person,index) in persons">
<span v-for="value in person"> {{ value }} </span>
</li>
<button @click.native="deleteQuote">
Delete
</button>
data: {
ingredients: ['meat', 'fruit', 'salad'],
persons: [
{name: 'Max', age: 27, color: 'red'},
{name: 'Mit', age: 47, color: 'red'},
{name: 'Foo', age: 37, color: 'red'},
]
},
methods: {
deleteQuote: function(person) {
this.persons.splice(index, 1);
}
}
})
答案 0 :(得分:0)
将按钮元素放在native
标记内,并删除index
修饰符,并将deleteQuote
作为参数传递给<li v-for="(person,index) in persons">
<span v-for="value in person"> {{ value }} </span>
<button @click="deleteQuote(index)">
Delete
</button>
</li>
方法:
index
该方法应以 methods: {
deleteQuote: function(index) {
this.persons.splice(index, 1);
}
}
作为参数来定义:
{{1}}