[Vuejs]-Vue.js – CORS error in local and production

4👍

If you read the second part in the error it says where the issue is.

Request header field access-control-allow-origin is not allowed by
Access-Control-Allow-Headers in preflight response

As you can see you need to allow access in preflight response. A preflight request is something the browser does before sending your actual GET/POST/etc request. In the devtools’ network tab you have 2 requests for the /login url. First one is a preflight using OPTIONS method.

To fix the issue you need to make sure your backend server returns 'Access-Control-Allow-Origin': 'http://localhost:8080' header in it’s response for OPTIONS requests. Currently it is specifying only allowed methods and headers. You don’t need to add those headers to your axios request.

👤Cray

Leave a comment