前端页面访问本地服务时出现如下错误提示:
No ‘Access-Control-Allow-Origin’ header is present on the requested resource. Origin ‘http://localhost:11000’ is therefore not allowed access.
原因是:浏览器的同源策略不允许跨域访问,也就是协议、地址、端口不同不可以访问。
解决:服务端代理,此处采用proxyTable解决,vue-cli提供的解决vue开发环境下跨域问题的方法,proxyTable的底层使用了http-proxymiddleware(https://github.com/chimurai/http-proxy-middleware),它是http代理中间件,它依赖node.js, 基本原理是用服务端代理解决浏览器跨域。
cms跨域解决原理:
1、访问页面http://localhost:11000/
2、页面请求http://localhost:11000/query
由于url由http://localhost:31001/query…改为“http://localhost:11000/query.",所以不存在跨域
3、通过proxyTable由node服务器代理请求 http://localhost:31001/cms.
服务端不存在跨域问
跨域问题解决
最新推荐文章于 2024-07-21 21:28:16 发布