• vue 跨域问题


    前段时间做一个vue打包成安卓和IOS的App,遇到了跨域问题,直接拿了之前项目的配置,却不起作用。

    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 CorsConfig implements WebMvcConfigurer {

    @Override
    public void addCorsMappings(CorsRegistry registry) {
    registry.addMapping("/**")
    .allowedOrigins("*")
    .allowCredentials(true)
    .allowedMethods("GET", "POST", "PUT", "DELETE", "OPTIONS")
    .maxAge(3600);
    }

    }
    但是还是不行,后面查明是因为之前项目nginx和项目在一个服务器,而APP的前端是在移动端的。解决方法有所不同,如下

    import org.springframework.context.annotation.Configuration;
    import org.springframework.http.HttpHeaders;
    import org.springframework.web.servlet.config.annotation.CorsRegistry;
    import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter;

    @Configuration
    public class LakeAppConfigurer extends WebMvcConfigurerAdapter {

    @Override
    public void addCorsMappings(CorsRegistry registry) {
    registry.addMapping("/**")
    .allowedOrigins("*")
    .allowCredentials(true)
    .allowedHeaders("*")
    .allowedMethods("GET", "POST", "DELETE", "PUT", "OPTIONS")
    .exposedHeaders(HttpHeaders.SET_COOKIE).maxAge(3600L)
    .maxAge(3600);
    }
    }
    完美解决。
    ---------------------
    作者:马克Markorg
    来源:CSDN
    原文:https://blog.csdn.net/csgarten/article/details/88395235
    版权声明:本文为博主原创文章,转载请附上博文链接!

  • 相关阅读:
    python 自定义模块路径问题
    好书一下
    批量修改shell文件
    查看内存占用,排名最高开始
    prosql写法示例
    curl base64 python 请求api地址进行测试服务是否正常
    linxu家目录$ 或者是家目录丢失
    docker 添加普通用户权限
    关系型数据库和非关系型数据库的内在区别
    MapperScan的工作,Spring-Mybatis怎么自动getMapper
  • 原文地址:https://www.cnblogs.com/sunsing123/p/10788427.html
Copyright © 2020-2023  润新知