【发布时间】:2018-07-02 15:00:47
【问题描述】:
我正在尝试传递要删除的记录和表的索引,以便可以更新它。
似乎删除工作正常,但从表中删除正确的记录却不行。
我尝试了一些变体并阅读了很多,但仍然无法完全弄清楚这一点,所以请寻求指导。
我的组件
//recordID - record to delete from API
// index - index in table
// console log returns correct info for both
onDelete (recordId, index) {
this.$store.dispatch('cases/deleteCase', recordId, index)
}
// also tried this.$store.dispatch('cases/deleteCase', (recordId, index)) but didn't work or delete
我的店里有
动作
deleteCase ({ commit, context }, data, index) {
console.log(data)
return new Promise ((resolve, reject) => {
//Delete works as expected
this.$axios.delete('/cases/' + data + '.json')
.then(
resolve(commit('DELETE_CASE', index))
)
.catch(e => {
context.error(e)
reject('/cases/')
})
})
},
我的突变
// delete a todo
DELETE_CASE (state, index) {
state.cases.splice(index, 1);
}
非常感谢
【问题讨论】: