zoukankan      html  css  js  c++  java
  • 前后端分离后,通讯问题 springboot + vue

    springboot + vue

    前端使用vue, 后端使用springboot

    分开后,必将带来跨越问题,网上有文章说,开发好的vue前端,可以放到springboot一起运行,确实这样挺好的,只需要修改几个配置,而且在部署的过程中也不需要部署两个应用,但是在开发的时候,还是需要分开来开发,所以跨域问题必须存在,网上有很多方法,可以去搜一下,但在这里我就使用我觉得最适合我的方式

    首先前端,几乎不用任何改动,按正常使用axios请求方式

    然后后端,加一个配置类就可以了,改成跨域,如下

    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 WebAppConfigurer implements WebMvcConfigurer {
    
        @Override
        public void addCorsMappings(CorsRegistry registry) {
            registry.addMapping("/**").allowedOrigins("*")
                    .allowCredentials(true).allowedMethods("GET", "POST").maxAge(3600 * 24);
        }
    }

    总结:这种方式最简单,有效,所以就使用这种方式了

  • 相关阅读:
    HDU1029 Ignatius and the Princess IV
    UVA11039 Building designing【排序】
    UVA11039 Building designing【排序】
    POJ3278 HDU2717 Catch That Cow
    POJ3278 HDU2717 Catch That Cow
    POJ1338 Ugly Numbers(解法二)
    POJ1338 Ugly Numbers(解法二)
    UVA532 Dungeon Master
    UVA532 Dungeon Master
    POJ1915 Knight Moves
  • 原文地址:https://www.cnblogs.com/oscar1987121/p/10496708.html
Copyright © 2011-2022 走看看