简体   繁体   中英

Axios.delete in React: `Error:DELETE chrome-extension://…`

I create the chrome extension in React . During request url delete , I received an error: Error: DELETE chrome-extension://ldkflkflkfklfkfksfk/[object%20Object] net::ERR_FILE_NOT_FOUND

I tried to do the Get method earlier. This method works. Also token, url are good.

In tab network in response headers I have Provisional headers are shown

delete = (id) => {

    const url = `https://applic.com/api/v1/todos/${id}?expand=createdBy`;
    const token = '12345'; 

    axios.delete({
      url: url,
      headers: { 'Authorization' : `Bearer ${token}` }
    }).then(function(response) {
      console.log(`Deleted: ${id}` );
    }).catch(function (error) {
      console.log(`error: ${id}`);
    });

    const filter = this.state.items.filter(item=> item.id !== id);

    this.setState({ 
      items: filter,
      isOpen: false
    });
}

The syntax for axios.delete is axios.delete(url[, config])

The API call should be:

axios.delete(
  url,
  { 
     headers: { 'Authorization' : `Bearer ${token}`
  }
})

Docs

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM