记录vue springboot 跨域采坑


vue配置 域名srcmain.js要与configindex.js一样


var axios = require('axios')
axios.defaults.baseURL = 'http://localhost:2020/api'
// 使请求带上凭证信息
axios.defaults.withCredentials = true


assetsSubDirectory: 'static',
assetsPublicPath: '/',
proxyTable: {
'/api': {
target: 'http://localhost:2020',
changeOrigin: true,
pathRewrite: {
'^/api': ''
}
}
},



spring 配置comevangdconfigMyWebConfigurer.java

@Override
public void addCorsMappings(CorsRegistry registry) {
//所有请求都允许跨域,使用这种配置方法就不能在 interceptor 中再配置 header 了
registry.addMapping("/**")
.allowCredentials(true)
.allowedOrigins("http://localhost:8080")
.allowedMethods("POST", "GET", "PUT", "OPTIONS", "DELETE")
.allowedHeaders("*")
.maxAge(3600);
}
原文地址:https://www.cnblogs.com/gaodi2345/p/13549064.html