在使用Vue+Springboot框架,前后端分离时,我们会遇到跨域的问题,也就是当你前端发送请求的时候,会报错:
Access to XMLHttpRequest at ‘http://xxxx.com/xxx’ from origin ‘null’ has been blocked by CORS policy: No ‘Access-Control-Allow-Origin’ header is present on the requested resource.
当在网页的控制台(console)上显示这个错误的时候就是出现跨域的问题了
那么跨域问题是什么呢?
跨域问题就是浏览器从一个域名的网页去请求另一个域名的资源时,域名、端口、协议任一不同,都是跨域
那么在这个框架下我们怎么解决跨域问题呢?
1、首先需要在vue-config.js里面的proxy里面添加配置,具体vue-config.js文件的配置,在我的另一篇文章中有讲解,附上链接:https://blog.csdn.net/weixin_51043896/article/details/119548881?spm=1001.2014.3001.5501
这里就讲proxy里面的配置了
devServer: {
/* 自动打开浏览器 */
open: false,
/* 设置为0.0.0.0则所有的地址均能访问 */
host: '0.0.0.0',
port: 8080,
https: fals