最近学了一下vue,尝试做一个管理网站,使用axios请求后台接口数据时,又难免掉进了跨域坑中,报错如下403:
根据报错提示“XMLHttpRequest has been blocked by CORS policy: No 'Access-Control-Allow-Origin' header is present on the requested resource.”,可以得知需要配置响应头“Access-Control-Allow-Origin”。
解决该方法,前后端分别检查,前端在config中是否进行了跨域配置,后台是否设置了响应头“Access-Control-Allow-Origin”:
总结一下,axios跨域问题:
1. 服务端不支持跨域,比如下面两种情况:
1. XMLHttpRequest has been blocked by CORS policy: No 'Access-Control-Allow-Origin' header is present on the requested resource.
2. No 'Access-Control-Allow-Origin' header is present on th