updateGame(e) {
e.preventDefault();
const game = {
id: this.state.games.id,
name: this.state.games.name,
price: this.state.games.price,
category: this.state.games.category
}
axios.put('https://localhost:5001/games/', game)
.then(res => console.log(res.data))
}
我有两个功能,分别称为更新和删除。删除已完成,但需要更新方面的帮助,以便我可以更改内容。 Error
在类的构造函数中。尝试像这样绑定updateGame
的上下文:
constructor(props) {
// // This binding is necessary to make `this` work in the callback
this.updateGame = this.updateGame.bind(this);
}
有关React中Handling Event的更多信息