springboot+VUE的session跨域

  • Post author:
  • Post category:vue
  • VUE

const service = axios.create({
  baseURL: process.env.VUE_APP_BASE_API,
  withCredentials: true,  // session跨域打开
  timeout: 3000
})
  • SpringBoot

@Configuration
public class WebConfig implements WebMvcConfigurer {
    @Override
    public void addCorsMappings(CorsRegistry registry) {
        registry.addMapping("/**")
                .allowedOriginPatterns("*")
                .allowCredentials(true)  // 这个必须打开
                .allowedMethods("GET", "POST", "PUT", "DELETE", "OPTIONS")
                .allowedHeaders("*")
                .maxAge(3600);
    }
}


版权声明:本文为weixin_42662249原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。