使用vue-admin-template封装的Axios时跨域问题

使用@CrossOrigin注解时,再用@RequestMapping会出现拦截失效

解决方法1:

如果是get请求那就用@GetMapping即可

解决方法2:

配置一个跨域配置类


import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.CorsRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

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

你可能感兴趣的:(Vue)