axios的跨域问题

axios在请求后端的api时,出现CORS(跨域资源共享),

出现错误

跨域请求Access to XMLHttpRequest at 'http://localhost:8080/api/user/login' from origin 'http://localhosthas 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

需要添加{headers: {'Access-Control-Allow-Origin': '*'}}

但是搞了很长时间发现,只要npm install cors --save

发布了46 篇原创文章 · 获赞 13 · 访问量 1万+

猜你喜欢

转载自blog.csdn.net/qq_39038793/article/details/103730417
今日推荐