我不懂.我几个小时以来一直在努力
我在Laravel中使用Vue.js并尝试向外部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)
});
}
}
Run Code Online (Sandbox Code Playgroud)
错误
MLHttpRequest无法加载 https://www.mollie.com/payscreen/select-method/JucpqJQses.请求的资源上不存在"Access-Control-Allow-Origin"标头.因此,不允许访问" https://payment.dev ".
我为我的后端安装了Laravel CORS包,并将中间件添加到我的路线中,例如
Route::group(['middleware' => 'cors'], function(){
Route::post('/api/chargeCustomer', 'Backend\PaymentController@chargeCustomer');
});
Run Code Online (Sandbox Code Playgroud)
但我仍然得到错误.我还尝试添加Vue Headers
Vue.http.headers.common['Access-Control-Allow-Origin'] = '*';
Vue.http.headers.common['Access-Control-Request-Method'] = '*';
Run Code Online (Sandbox Code Playgroud)
具有相同的结果/错误.
有人能告诉我我做错了什么吗?