参考:https://blog.csdn.net/bohu83/article/details/114046354
一 问题现象
??
二 新增拦截器代码
以下为springboot bean注入方式。
??
三 在原来的拦截器配置增加配置
注意setorder 数字越小优先级越高。这个放在@Configuration 类里面。
??
四 NG配置
配置内容如下:
location / {
add_header Access-Control-Allow-Origin *;
add_header Access-Control-Allow-Methods 'GET, POST, OPTIONS';
add_header Access-Control-Allow-Headers 'DNT,X-Mx-ReqToken,Keep-Alive,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type,Authorization';
if ($request_method = 'OPTIONS') {
return 204;
}
}
五 VUE前端配置
配置内容如下:
$.ajax({
url: "https://b.com/method",
type: 'POST',
data: requestParams,
dataType: 'json',
xhrFields: {
withCredentials: true
},
crossDomain: true,
async: false,
...
注:容易出问题的地方,url 只写path,不写明HTTP协议。参数不加上跨域请求。
??
??