javascript - Window.locatin 防止数据被删除
问题描述
我有一个按钮,按下时我想删除对象。这是我的按钮:
<Button onClick={this.handleDelete.bind(this)}>
Delete
</Button>
这是我的handleDelete
:
handleDelete() {
axios
.delete(
`http://proiectdepozite.laravel/api/clienti/${this.state.client.id}`
)
.then((window.location = "/clienti"))
.catch(error => console.log(error));
}
现在,如果我按下按钮,它会将我重定向到我想要的位置,但它不会删除任何内容。我尝试注释掉.then(....)
它,它应该可以正常工作。错误在哪里?
解决方案
axios.delete('url', { data: payload }).then(
// Observe the data keyword Very important
// payload is the request body
()=>(window.location = "/clienti")//you can pass as pipe function
)
推荐阅读
- javascript - 是否可以在 HighChartJS 中创建分组条形图?
- yii2 - yii2如何查看自己的实体?
- flutter - 在颤动中显示和隐藏弹出窗口
- php - 如何使用 ODBC 通过 PHP 连接 Paradox DB?
- python - Python中有没有办法逐个读取文本文件?
- android - 如何使用 API 提供的颜色以编程方式更改 colorPrimary?
- javascript - Google Content Api for Shopping - 只列出想要的产品功能
- python - Python 3:当本地模块存在同名时导入核心模块?
- c# - Visual Studio 中的 IIS-Express 错误 - 无法运行项目
- android - 运行我的颤振应用程序时显示白色空白屏幕