【发布时间】:2021-12-10 05:01:38
【问题描述】:
我正在使用 Vue 3.0.0 和 Axios 0.21.1。我想根据id删除JSON文件中的数据。添加和获取没有问题,但是当我想删除它时,我的代码出现以下错误。
Uncaught TypeError: Cannot read properties of undefined (reading 'id')
这是我的删除方法:
deleteToDo(todoList){
axios.delete(`http://localhost:3000/todoList/${todoList.id}`).then(response_delete =>{
console.log(response_delete)
})
.catch(error => {
console.log(error)
})
}
添加方法:
addToDo(e){
const sendData = {
description : e.target.value,
date : new Date()
}
axios.post('http://localhost:3000/todoList', sendData).then(response_result =>{
console.log(response_result)
})
},
【问题讨论】: