has been blocked by CORS policy: Response to preflight request doesn't pass access control check: No 'Access-Control-Allow-Origin' header is present on the requested resource

出现这个,就是跨域问题了,我是在vue用axios直接发送请求向java后台的过程中出现的

然后我是在后端中解决的代码如下加上下面几个代码即可

@Configuration
public class WebConfig implements WebMvcConfigurer{


    @Override
    public void addCorsMappings(CorsRegistry registry) {
        // 设置允许跨域的路径
        registry.addMapping("/**")
            // 设置允许跨域请求的域名
            .allowedOrigins("*")
            // 是否允许证书
            .allowCredentials(true)
            .allowedMethods("*")
            .maxAge(3600);
    }

        ...
}

 

has been blocked by CORS policy: Response to preflight request doesn't pass access control check: No 'Access-Control-Allow-Origin' header is present on the requested resource

上一篇:To search for alternate channels that may provide the conda package you’re looking for, navigate解决记录


下一篇:使用SQL Server 2012创建和删除数据库