未捕获(承诺中)类型错误:无法读取未定义的属性(读取“数据”)

问题描述 投票:0回答:4

我正在构建 CRUD 功能,并在前几天使用组件中的相同代码进行创建,但现在它给出了错误:

Unhandled Rejection (TypeError): Cannot read properties of undefined (reading 'data')

我在验证时遇到错误,不确定它是否与道具有关。这是存在错误的代码:

> 30 |     const errorResponse = err.response.data.errors;
 console.log(errorResponse)
     | ^  31 |     const errorArr = [];
  32 |     for (const key of Object.keys(errorResponse)) {
  33 |         errorArr.push(errorResponse[key].message)```

Is anyone familiar with this issue and knows how to fix it?
javascript reactjs validation
4个回答
2
投票

问题可能来自将 API 连接到应用程序的 URL,因此无法从数据库检索数据


1
投票

您试图读取不存在的对象的数据。

err.response.data

尝试

console.log(err)
console.log(err.response)
您可能会发现您的回答有问题。


-1
投票

我使用try和catch来解决这个问题


-8
投票

世界你好,这是测试消息

© www.soinside.com 2019 - 2024. All rights reserved.