解决vue+springboot可能遇到的跨域问题和sessionid每次不同问题

1.跨域问题

在配置类中添加

   /*跨域问题*/
    @Override
    public void addCorsMappings(CorsRegistry registry) {
        registry.addMapping("/**")
                .allowedOrigins("*")
                .allowedMethods("GET", "HEAD", "POST", "PUT", "DELETE", "OPTIONS")
                .allowCredentials(true)
                .maxAge(3600)
                .allowedHeaders("*");
    }

2.sessionid每次不同问题

前端

// 允许携带cookie
axios.defaults.withCredentials = true

后端
就是上边添加的那个

  .allowCredentials(true)

你可能感兴趣的:(vue,vue,spring,boot)