相关疑难解决方法(0)

Vuejs和Laravel Post请求CORS

我不懂.我几个小时以来一直在努力

我在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)

具有相同的结果/错误.

有人能告诉我我做错了什么吗?

cors laravel vue.js vue-resource

9
推荐指数
1
解决办法
4646
查看次数

标签 统计

cors ×1

laravel ×1

vue-resource ×1

vue.js ×1