springboot+vue解决跨域问题
后台添加过滤器,允许跨域@Configurationpublic class GlobalCorsConfig {@Beanpublic CorsFilter corsFilter() {CorsConfiguration corsConfiguration = new CorsConfiguration();corsConfigurat...
·
后台添加过滤器,允许跨域
@Configuration
public class GlobalCorsConfig {
@Bean
public CorsFilter corsFilter() {
CorsConfiguration corsConfiguration = new CorsConfiguration();
corsConfiguration.addAllowedOrigin("*");
corsConfiguration.addAllowedHeader("*");
corsConfiguration.addAllowedMethod("*");
UrlBasedCorsConfigurationSource configSource = new UrlBasedCorsConfigurationSource();
configSource.registerCorsConfiguration("/**", corsConfiguration);
return new CorsFilter(configSource);
}
}
前台
在config的index.js的proxyTable中加入拦截,拦截/api请求,替换成target中的请求,
比如原始请求是/api/hello.pub,则会替换成http://192.168.33.104:8086/hello.pub。
proxyTable: {
'/api':{
target: 'http://192.168.33.104:8086',
changeOrigin:true,
pathRewrite:{
'^/api':''
}
}
},
更多推荐
已为社区贡献1条内容
所有评论(0)