我应该使用分页吗?每当我单击此按钮<Delete>
时,它就会抛出
TypeError:无法读取未定义的属性'map'。
之间是否有任何关联>
axios => getData => setState => .map => return elmItem
谢谢!
class ContentComponent extends Component {
constructor(props) {
super(props);
this.state = {
items: [],
};
}
componentDidMount() {
axios
.get("http://localhost:4000/api/todos")
.then(res => this.setState({ items: res.data.result }))
.catch(error => console.log(error));
}
handleDelete = value => {
axios
.delete(`http://localhost:4000/api/todos/${value}`)
.then(res => this.setState({items: res.data.result}))
.catch(error => console.log(error));
};
render() {
let { items } = this.state;
const elmItem = items.map((item, index) => {
return <TableComponent item={item} key={index} index={index} handleDelete={this.handleDelete}/>;
});}
<table className="table">
<tbody>{elmItem}</tbody>
</table>
我应该使用分页吗?每当我单击此按钮
使用console.log()调试handleDelete