我不明白.几个小时以来我一直在努力解决这个问题
我正在使用Vue.与Laravel一起使用js,并try 向外部API发出POST请求.
但我的Vue POST请求中总是出现CORS错误
methods: {
chargeCustomer(){
this.$http.post('/api/chargeCustomer', this.payment).then(function (response) {
console.log(response.data)
},function (response) {
console.log(response.data)
});
}
}
ERROR
无法加载MLHttpRequest
我为我的后端安装了Laravel CORS Package,并将中间件添加到我的路由中,例如
Route::group(['middleware' => 'cors'], function(){
Route::post('/api/chargeCustomer', 'Backend\PaymentController@chargeCustomer');
});
但我仍然得到了错误.我还try 添加带有
Vue.http.headers.common['Access-Control-Allow-Origin'] = '*';
Vue.http.headers.common['Access-Control-Request-Method'] = '*';
同样的结果/错误.
有人能告诉我我做错了什么吗?