【问题标题】:Delete request with axios -Vue.js使用 axios -Vue.js 删除请求
【发布时间】:2020-03-08 00:01:57
【问题描述】:

我在 Vue.js 客户端中运行 DELETE 请求时遇到问题。这是我现在的代码,我只是对链接进行硬编码以便试用。

  deleteCompany(){
    axios.delete('http://localhost:9292/companies/1')
    .then(response =>{
      console.log(response);
    });
  }

在后端,我有一个用 Sinatra 构建的 Ruby 服务器,这是 DELETE 的方法:

#delete a company
delete '/companies/:id'do 
  content_type :json
  company = Company.get params[:id]
  if company.destroy
    status 200
    json'Company was deleted'
  else
    status 500
    json 'There was problem removing the company'
  end
end

我尝试使用 curl 和 Postman,它正在工作,但是当我尝试从客户端执行此操作时,它给了我一个 CORS 错误,尽管 POST 等其他方法正在工作:

Cross-Origin Request Blocked: The Same Origin Policy disallows reading the remote resource at http://localhost:9292/companies/1. (Reason: Did not find method in CORS header ‘Access-Control-Allow-Methods’).

Cross-Origin Request Blocked: The Same Origin Policy disallows reading the remote resource at http://localhost:9292/companies/1. (Reason: CORS request did not succeed).

【问题讨论】:

    标签: ruby vue.js cors axios sinatra


    【解决方案1】:
    猜你喜欢
    • 1970-01-01
    • 2018-12-24
    • 2018-09-15
    • 2018-04-10
    • 1970-01-01
    • 2017-11-03
    • 2017-06-06
    • 2018-11-04
    • 1970-01-01
    相关资源
    最近更新 更多