I am trying to make a simple axios request which look like this (i'm working with Vue.js):
axios
.get(url),
.then(({ data }) => {
// ...
})
.catch(err => console.log(err))
But I get the following error:
Access to XMLHttpRequest at 'url' from origin 'http://localhost:8080' has been blocked by CORS policy: Response to preflight request doesn't pass access control check: No 'Access-Control-Allow-Origin' header is present on the requested resource.
Error: Network Error
at createError (createError.js?2d83:16)
at XMLHttpRequest.handleError (xhr.js?b50d:84)
I have already tried adding the following headers, but it still doesn't work
headers: {
"Access-Control-Allow-Origin": "*"
"mode":"no-cors"
}
but if I try to make the request via browser (simply by copying and pasting the url) everything works fine.
Would anyone know how to help me? Thanks so much!