前端在header中传递了token,导致提示header跨域,可以在nginx中做如下配置:
add_header ‘Access-Control-Allow-Origin’ ‘*’;
add_header ‘Access-Control-Allow-Credentials’ ‘true’;
add_header ‘Access-Control-Allow-Methods’ ‘POST, GET, PUT, OPTIONS, DELETE’;
add_header ‘Access-Control-Allow-Headers’ ‘*’;
重要的是这句:add_header ‘Access-Control-Allow-Headers’ ‘*’;
之前只是配置了允许一部分:add_header ‘Access-Control-Allow-Headers’ ‘DNT,X-CustomHeader,Keep-Alive,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type’;
如果不方便配置所有,增加上允许token也是可以的。
还以为是草莓开发框架thinkphp6版本的问题,原来不是。