【发布时间】:2022-07-14 17:20:55
【问题描述】:
为什么我的删除按钮不会删除记录?我正在使用 mern 堆栈。在 console.log 代码 sn-p 2 之后似乎没有设置状态。代码 sn-p 3 映射数据,就好像该记录从未被删除一样。
recordList.js
componentDidMount() {
axios
.get("https://julio-mern-app.herokuapp.com/record/")
.then((response) => {
this.setState({ records: response.data });
})
.catch(function (error) {
console.log(error);
});}
deleteRecord(id) {
axios.delete("https://julio-mern-app.herokuapp.com/" + id).then((response) => {
console.log(response.data);
})
this.setState({
record: this.state.records.filter((el) => el._id !== id),
});}
recordList() {
return this.state.records.map((currentrecord) => {
return (
);
});}