Ruby 使用axios-Vue.js删除请求
在Vue.js客户端中运行删除请求时出现问题。这是我的代码,现在我只是硬编码的链接,以尝试它Ruby 使用axios-Vue.js删除请求,ruby,vue.js,cors,axios,sinatra,Ruby,Vue.js,Cors,Axios,Sinatra,在Vue.js客户端中运行删除请求时出现问题。这是我的代码,现在我只是硬编码的链接,以尝试它 deleteCompany(){ axios.delete('http://localhost:9292/companies/1') .then(response =>{ console.log(response); }); } 在后端,我有一个内置Ruby和Sinatra的服务器,这是删除的方法: #delete a company delete '
deleteCompany(){
axios.delete('http://localhost:9292/companies/1')
.then(response =>{
console.log(response);
});
}
在后端,我有一个内置Ruby和Sinatra的服务器,这是删除的方法:
#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).
您需要这样的东西来为服务器配置跨源请求 这里也是一篇好文章