Vuejs and Laravel Post Request CORS

后端 未结 2 1757
孤独总比滥情好
孤独总比滥情好 2021-01-12 01:17

I dont get it. I am struggling with this since hours

I am using Vue.js with Laravel and try to make a POST Request to an external API.

But i am always getti

2条回答
  •  太阳男子
    2021-01-12 02:15

    Other way (without creating a new laravel middleware) is add these headers at the begining of your routes.php

    header('Access-Control-Allow-Origin:  *');
    header('Access-Control-Allow-Methods:  POST, GET, OPTIONS, PUT, DELETE');
    header('Access-Control-Allow-Headers:  Content-Type, X-Auth-Token, Origin, Authorization');
    

    and add this before your interceptors on vue: Vue.http.options.crossOrigin = true

提交回复
热议问题