Javascript 为什么在尝试运行代码时会出现类型错误?
我正在试图弄清楚为什么我得到的Javascript 为什么在尝试运行代码时会出现类型错误?,javascript,reactjs,debugging,Javascript,Reactjs,Debugging,我正在试图弄清楚为什么我得到的无法分解“this.props.customer”的属性“id”,因为它是未定义的。错误。从外观上看,我的代码似乎是正确的,但尽管如此,我仍然得到了前面提到的错误。有什么我忽略的微小的东西吗 下面是CustomerList.js文件: import React, { Component } from "react"; import Customer from "./Customer"; class CustomerList extends Component {
无法分解“this.props.customer”的属性“id”,因为它是未定义的。
错误。从外观上看,我的代码似乎是正确的,但尽管如此,我仍然得到了前面提到的错误。有什么我忽略的微小的东西吗
下面是CustomerList.js
文件:
import React, { Component } from "react";
import Customer from "./Customer";
class CustomerList extends Component {
render() {
const customers = this.props.customers;
return(
<div className="data">
<table className="ui celled table">
<thead>
<tr>
<th style={{ width: '50px', textAlign: 'center' }}>#</th>
<th>Name</th>
<th>E-mail</th>
<th style={{ width: '148px' }}>Action</th>
</tr>
</thead>
<tbody>
{
customers.map(customer => {
return <Customer customer={customer} key={customer.id} />;
})
}
<Customer/>
</tbody>
</table>
</div>
);
}
}
export default CustomerList;
在
地图的下方
部分有一个
<Customer/>
对
Customer
组件的调用没有参数,因此Customer
未定义。这就是为什么会出现错误。原因是this.props.customer
未定义-并且您发布的代码并不表示它存在。您可以将console.log(this.props.customer)
添加到customer
渲染吗?如果客户组件呈现不止一次,您是否随时记录未定义
?哇。。。谢谢你,伙计。这件事我坚持了两天:)我非常感激。
<Customer/>