1.后端設置
Access-Control-Allow-Credentials 設置為true
設置:Access-Control-Allow-Origin
2.前端設置
設置:withCredentials: true
以axios為例:在request config中設置:withCredentials: true
以上參考:https://stackoverflow.com/questions/46288437/set-cookies-for-cross-origin-requests
3.設置domain的問題:.
31.如果cookies中的domain有端口信息,chrome瀏覽器會自動過濾掉這個cookie。
3.2.按設計,domain 必須有至少兩個點,否則瀏覽器會認為該domain是非法的。
3.3.在localhost上,domain應該省略,設置為null、‘’,flase 不夠
可以嘗試不設置domain,或者是為null、‘’、false
我設置了domain為null,可以;具體原因不知。
