前端
// request拦截器
service.interceptors.request.use(
config => {
config.headers.自定义参数= store.state.自定义参数
// 让每个请求携带自定义token 请根据实际情况自行修改
config.headers.token = localStorage.getItem(‘token’) ?? ‘’‘’
console.log(‘request拦截器’)
return config
},
后端拦截器
@Override
public void addCorsMappings(CorsRegistry registry) {
registry.addMapping(“/**”)
.allowedHeaders(“token”,“Content-Type”,“自定义参数”)
.allowedOriginPatterns(“*”)
.allowCredentials(true)
.allowedMethods(“GET”, “POST”, “PUT”, “DELETE”, “OPTIONS”);
}