【问题标题】:Uncaught Type Error When I want to delete by ID当我想按 ID 删除时未捕获的类型错误
【发布时间】: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)
            })
            
        },

【问题讨论】:

    标签: axios vuejs3


    【解决方案1】:

    根据报错信息,你传递给deleteToDo方法的todoList应该是未定义的,你可以在那里添加一个控制台来检查是否是这个原因。

    并且猜测您应该将 todoItem 而不是 todoList 传递给该方法?由于您只发布了少量代码...

    【讨论】:

      猜你喜欢
      • 2016-03-02
      • 1970-01-01
      • 1970-01-01
      • 2022-01-18
      • 2016-10-28
      • 2012-12-24
      • 1970-01-01
      • 2012-12-29
      • 2014-12-07
      相关资源
      最近更新 更多