RELATEED CONSULTING
相关咨询
选择下列产品马上在线沟通
服务时间:8:30-17:00
你可能遇到了下面的问题
关闭右侧工具栏

新闻中心

这里有您想知道的互联网营销解决方案
SpringBoot和Vue中跨域请求的原理是什么

这期内容当中小编将会给大家带来有关SpringBoot和Vue中跨域请求的原理是什么,文章内容丰富且以专业的角度为大家分析和叙述,阅读完这篇文章希望大家可以有所收获。

让客户满意是我们工作的目标,不断超越客户的期望值来自于我们对这个行业的热爱。我们立志把好的技术通过有效、简单的方式提供给客户,将通过不懈努力成为客户在信息化领域值得信任、有价值的长期合作伙伴,公司提供的服务项目有:域名申请、网页空间、营销软件、网站建设、龙门网站维护、网站推广。

使用Spring Boot + Vue 做前后端分离项目搭建,实现登录时,出现跨域请求

Access to XMLHttpRequest at 'http://localhost/open/login' from origin 'http://localhost:8080' has been blocked by CORS policy: No 'Access-Control-Allow-Origin' header is present on the requested resource.

Vue中使用的Axios,配置main.js文件

Axios.defaults.baseURL = 'http://localhost:80'Axios.defaults.headers['Content-Type'] = 'application/x-www-form-urlencoded;charset=UTF-8'Axios.defaults.withCredentials = true

Spring Boot中重写WebMvcConfigurationSupport的方法addCorsMapping

import org.springframework.context.annotation.Configuration;import org.springframework.web.servlet.config.annotation.CorsRegistry;import org.springframework.web.servlet.config.annotation.WebMvcConfigurationSupport;@Configurationpublic class WebMvcConfig extends WebMvcConfigurationSupport{  @Override  public void addCorsMappings(CorsRegistry registry) {    String[] origins = {"http://localhost:8080"};    registry.addMapping("/**")        .allowedOrigins(origins)        .allowCredentials(true)        .allowedMethods("*")        .allowedHeaders("*")        .maxAge(3600);  }}

上述就是小编为大家分享的SpringBoot和Vue中跨域请求的原理是什么了,如果刚好有类似的疑惑,不妨参照上述分析进行理解。如果想知道更多相关知识,欢迎关注创新互联行业资讯频道。


本文名称:SpringBoot和Vue中跨域请求的原理是什么
文章路径:http://sczitong.cn/article/gcieig.html