React中的Axios.delete:`Error:DELETE chrome-extension:// ...

时间:2019-06-28 11:45:30

标签: javascript reactjs google-chrome-extension ecmascript-6 axios

我在React中创建chrome扩展。在请求网址delete期间,我收到一个错误:Error: DELETE chrome-extension://ldkflkflkfklfkfksfk/[object%20Object] net::ERR_FILE_NOT_FOUND

我之前尝试过使用Get方法。此方法有效。令牌,URL也很好。

network的标签response headers中,我有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
    });
}

1 个答案:

答案 0 :(得分:1)

axios.delete的语法为axios.delete(url[, config])

API调用应为:

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

Docs