zoukankan      html  css  js  c++  java
  • 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
    版权声明:本文为博主原创文章,转载请附上博文链接!

  • 相关阅读:
    数据库设计——多表之间的关系
    约束
    DQL
    DML
    DDL
    Mysql——基础
    IT大牛关注链接
    deepin20安装Python3.85
    Python中的模块
    python中的装饰器
  • 原文地址:https://www.cnblogs.com/sunsing123/p/10788427.html
Copyright © 2011-2022 走看看