首页 > 编程知识 正文

跨域的解决方法,前端跨域怎么解决

时间:2023-05-03 23:30:16 阅读:25557 作者:1092

问题背景下的Axios不允许跨域访问。 别说域间,就是端口间也不行。 例如,某个项目的我的本地vue前端前端frontEnd是localhost:8889,Java后台backEnd是localhost:8888

33558 www.Sina.com/: accesstoxmlhttprequestat ' http://localhost 33608888/cert/cert company/list2' from origin ' 333http://

axios.post (http://localhost :8888/cert/cert company/list2),JSON.stringify (this.search param ) (.then ) }.catch (功能(error ) ) console.log ) error; ); 此时有两个方案:

修改前端,支持跨域。 通过代理的形式,当然这样的是伪跨域,但是如果后端没有限制的话就很有用了。 修改后台,支持跨域。 另外,限制域间的使用。 不要在这里讨论,看过去的处理方法。

SpringBoot跨域筛选器配置允许跨域访问

SpringCloudApiGateway支持Cors跨域请求解决方案main.js部署了axios

//axiosbyzhengkai.blog.csdn.netimportaxiosfrom ' axios ' vue.prototype.$ axios=axiosaxios.defaults.base URL 设置xxx' config.index.js改造proxyTable部分,部署虚拟代理,请求target地址时直接写在/api上即可。

dev:{env:require; './dev.env ',port: 8889,autoOpenBrowser: true, 资产辅助目录: '静态代理表: {//axios跨域改造by zhengkai.blog.csdn.net '/API ' : (目标: ) 在您请求的第三方接口changeOrigin:true,//本地创建虚拟服务端,发送请求的数据,同时接收请求的数据。 这样,就可以替换pathrewrite3360(//路径改写' ^/api':'//target中的请求地址,以使服务端与服务端进行数据交换时不存在域间问题也就是说,在/api=/target中,请求target这个地址时直接写/API即可。 },//csssourcemapsoffbydefaultbecauserelativepathsare ' buggy '//with this option, accordingtothecss-loader自述//https://github.com/web pack/CSS-loader # source maps (/in our experience, they gence//justbeawareofthisissuewhenenablingthisoption.cssourcemap : false }业务. vue修改请求是/api封装的开头。 (但是,如果借口中包含/api关键字,则建议使用其他关键字() ) ) ) 652 )

//axios跨域为by zhengkai.blog.csdn.netaxios.post ('/cert company/list2',JSON.stringify (this.search parararany ) ); 验证效果的要求无误,没有令人困扰的no ' access-control-allow-origin ' headerisprespresentontherequestedresource .的错误。

版权声明:该文观点仅代表作者本人。处理文章:请发送邮件至 三1五14八八95#扣扣.com 举报,一经查实,本站将立刻删除。