前后端分离跨域每次请求sessionId不一致解决 springboot解决跨域问题

后台:完整的跨域代码

@Configuration
public class WebMvcConfig extends WebMvcConfigurerAdapter {

  @Override
  public void addCorsMappings(CorsRegistry registry) {
    registry.addMapping("/**").allowedHeaders("*")
      .allowedMethods("*")
      .allowedOrigins("*")
      .allowCredentials(true);
  }
}

前台:

vue:在main.js import的下面加上这个代码

axios.defaults.withCredentials = true

jquey:在使用ajax的时候一定要设置    

xhrFields:{withCredentials:true}

参考资料:https://blog.csdn.net/qq_38082304/article/details/79914994

猜你喜欢

转载自blog.csdn.net/weixin_40760196/article/details/81169528