因为项目登录信息放到session中,vue不同的接口访问会有不同的sessionId,解决办法是在main.js中加入
axios.defaults.withCredentials = true
但是这样导致了一个跨域问题,后端Controller上加入@CrossOrigin不起作用了
所以后端项目可以加入CorsConfig接口,这样就完美解决了跨域问题
package com.face.server.config;
import org.springframework.boot.web.servlet.FilterRegistrationBean;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.core.Ordered;
import org.springframework.web.cors.CorsConfiguration;
import org.springframework.web.cors.UrlBasedCorsConfigurationSource;
import org.springframework.web.filter.CorsFilter;
/**
* Created by lin on 2019/7/14.
*/
@Configuration
public class CorsConfig {
private CorsConfiguration buildConfig() {
CorsConfiguration corsConfiguration = new CorsConfiguration();
corsConfiguration.addAllowedOrigin("*");
corsConfiguration.ad