一、报错内容如下:
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设置
网友评论