首页 > 解决方案 > 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(....)它,它应该可以正常工作。错误在哪里?

标签: javascriptreactjsaxios

解决方案


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


)

推荐阅读