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
    版权声明:本文为博主原创文章,转载请附上博文链接!

  • 相关阅读:
    iOS面试题
    iOS-block
    iOS开发设计模式
    iOS-宏定义
    正则表达式(转)
    iOS-textfield控制光标开始位置
    initWithNibName&initWithCoder &awakeFromNib&UIView常见属性方法
    iOS应用生命周期
    iOS-app发布新版本步骤
    iOS从App跳转至系统设置菜单各功能项
  • 原文地址:https://www.cnblogs.com/sunsing123/p/10788427.html
Copyright © 2011-2022 走看看