我正在构建 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?
问题可能来自将 API 连接到应用程序的 URL,因此无法从数据库检索数据
您试图读取不存在的对象的数据。
err.response.data
尝试
console.log(err)
和console.log(err.response)
您可能会发现您的回答有问题。
我使用try和catch来解决这个问题
世界你好,这是测试消息