has been blocked by CORS policy: Response to preflight request doesn‘t pass access control check: N

CORS跨域问题

:8080/#/pages/loginRegist/loginRegist:1 Access to XMLHttpRequest at ‘http://127.0.0.1:8099/passport/getSMSCode?mobile=13812345678’ from origin ‘http://localhost:8080’ 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.

//解决跨域问题
@SpringBootApplication
public class MyWebConfigurer implements WebMvcConfigurer {
    @Override
    public void addCorsMappings(CorsRegistry corsRegistry){
        /**
         * 所有请求都允许跨域,使用这种配置就不需要
         * 在interceptor中配置header了
         */
        corsRegistry.addMapping("/**")
                .allowCredentials(true)
                .allowedOrigins("http://localhost:8080")
                .allowedMethods("POST", "GET", "PUT", "OPTIONS", "DELETE")
                .allowedHeaders("*")
                .maxAge(3600);
    }
}

你可能感兴趣的:(#,springboot,java,知识,java,服务器,开发语言,spring,spring,boot)