javascript - 我的删除功能将无法使用反应
问题描述
删除按钮不使用反应
我可以在邮递员中执行 axios 调用来删除,但是当我尝试在前端进行响应时,我的删除功能将不起作用。
<button onSubmit = {this.handleSubmit}> Delete </button>
// below is the function I'm trying to use to delete an item from my database
async handleSubmit(event) {
event.preventDefault()
await axios.delete(`http://localhost:3000/brands/${this.props.match.params.brand_id}/guitars/${this.props.match.params.id}`)
console.log("pressed")
}
// the backend is built in ruby and in postman the delete route works
我不明白为什么按钮不起作用。
我希望在刷新页面时收到错误,因为特定项目(吉他)和 url 不再在数据库中,或者,我的重定向路由将起作用,我将被重定向到显示所有项目(吉他)的页面特定品牌。
解决方案
改为 onClick 不是 onSubmit。按钮没有 onSubmit 事件
async handleSubmit(event) {
event.preventDefault()
await axios.delete()
console.log("pressed")
}
render() {
return (
<div>
<Hello name={this.state.name} />
<p>
Start editing to see some magic happen :)
</p>
<button onClick={(e) => this.handleSubmit(e)}> Delete </button>
</div>
);
}
代码在这里
推荐阅读
- python-2.7 - python2.7和python3.6打开音频文件的区别?
- reactjs - 打字稿键入类组件的连接道具[重复]
- python - 传递列名列表以提取熊猫数据框中的数据子集时出错
- javascript - 在 Node Js Post 处理中无法获取 /url 错误
- react-native - 如果高度为百分比,如何根据父组件的高度设置文本的字体大小?
- prometheus-alertmanager - alertmanager 随机获取错误消息意外状态代码 422
- python - 有没有办法将多个 Pandas 行聚合成带有额外列的单行?
- postgresql - ORACLE "connect by" 到 POSTGRESQL 的转换
- java - 仅将列入白名单的属性从 JSON 转换为 Map
- pyqt5 - 文件 XML def importDOM(self,way)