在前后端分离开发的时候就会遇到跨域的问题,在本地调试的时候可能不会出现什么太大的问题,但是上线部署的时候难免会遇到问题
不过这种跨域的问题还是最好在后端解决
https://www.kancloud.cn/manual/thinkphp5_1/489844
在我们的route目录下的route.php,可以分组配置路由
这个是默认的跨域设置,当然这个都可以自己添加的
Access-Control-Allow-Origin:*
Access-Control-Allow-Methods:GET, POST, PATCH, PUT, DELETE
Access-Control-Allow-Headers:Authorization, Content-Type, If-Match, If-Modified-Since, If-None-Match, If-Unmodified-Since, X-Requested-With
添加可以像这样的
Route::get('new/:id', 'News/read')
->ext('html')
->header('Access-Control-Allow-Origin','thinkphp.cn')
->header('Access-Control-Allow-Credentials', 'true')
->allowCrossDomain();
原文链接:https://www.cnblogs.com/guizimo/p/13278471.html