浏览器报错:Response to preflight request doesn't pass access control check: No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'http://localhost:8081' is therefore not allowed access. The response had HTTP status code 403.
代码:
this.$axios({
method: "get",
url: "http://192.168.3.10:8080/MayaCloud_Login/getPermissionTree",
headers:{
sessionUser :sessionStorage.getItem("token")
},
})
是因为你为你的请求头部添加了一个sesstionUser,并不在简单请求的范围内,所以浏览器会发送一个预检请求
详细简单请求和复杂请求区别看这里
https://developer.mozilla.org...
解决办法很简单,后台为你设置的头添加跨域允许就可以了,要在对预检请求的处理里添加