我现在的代码是这样的:
// Todos.vue
<a class="list-group-item" v-bind:class="{ 'completed': todo.completed }" v-for="(todo, index) in todos">
<button class="btn btn-xs btn-danger pull-right" v-on:click='destroy(todo, index)'title="删除">✘</button>
</a>
destroy(todo, index) {
this.$store.dispatch('deleteTodo', { todo, index })
},
// main.js
mutations: {
delete_todo (state, index) {
state.todos.splice(index, 1)
},
},
actions: {
deleteTodo (store, payload) {
Vue.axios.delete('http://localhost:8000/api/todo/' + payload.todo.id + '/delete')
.then((response) => {
store.commit('delete_todo', payload.index)
});
},
}
并且测试能正常删除,所以不懂“index 是 todo 的 id”是啥意思,怎样操作会出现 @博闻慎思 说的问题呢?