美文网首页
解决SpringBoot Vue 跨域问题

解决SpringBoot Vue 跨域问题

作者: 小沈新手 | 来源:发表于2019-01-11 16:13 被阅读21次

一、报错内容如下:

Failed to load http://192.168.1.111:8888/console/good/front/classList: 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. If an opaque response serves your needs

二、在后台添加如下文件

@Configuration

public class MvcConfigimplements WebMvcConfigurer {

@Override

    public void addCorsMappings(CorsRegistry registry) {

// 这里匹配了所有的URL,允许所有的外域发起跨域请求,允许外域发起请求任意HTTP Method,允许跨域请求包含任意的头信息。

        registry.addMapping("/**")

.allowedHeaders("*")

.allowedMethods("*")

.allowedOrigins("*")

.allowCredentials(true);

}

}

即可解决,当然也可以在nginx设置

相关文章

网友评论

      本文标题:解决SpringBoot Vue 跨域问题

      本文链接:https://www.haomeiwen.com/subject/hdbxdqtx.html