Axios更新错误。需要更改的内容

问题描述 投票:0回答:1
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

reactjs axios updates edit put
1个回答
0
投票

在类的构造函数中。尝试像这样绑定updateGame的上下文:

constructor(props) {
   // // This binding is necessary to make `this` work in the callback
   this.updateGame = this.updateGame.bind(this);
}

有关React中Handling Event的更多信息

© www.soinside.com 2019 - 2024. All rights reserved.