0

Helo,am new in Vue.js,am using laravel and vue to practice some crud application. It does not submit nor query data,, It gives this error when i view on the chrome;

Access to XMLHttpRequest at 'http://localhost:8000/items' from origin 'http://laravelvue2.test' has been blocked by CORS policy: No 'Access-Control-Allow-Origin' header is present on the requested resource.

  • Possible duplicate of [Vuejs and Laravel Post Request CORS](https://stackoverflow.com/questions/37860851/vuejs-and-laravel-post-request-cors) – King Julien Mar 06 '19 at 12:42

1 Answers1

0

You need to respond with Access-Control-Allow-Origin header when accessing backend from differend domain. In this example the value of Access-Control-Allow-Origin must be http://localhost:8000.

Adding header to your response is quite easy in laravel: https://laravel.com/docs/5.7/responses#attaching-headers-to-responses

You can also use this library: https://github.com/barryvdh/laravel-cors

King Julien
  • 10,981
  • 24
  • 94
  • 132