详解vue或uni-app的跨域问题解决方案-创新互联
常见解决方案有两种
服务器端解决方案
服务器告诉浏览器:你允许我跨域
具体如何告诉浏览器,请看:
// 告诉浏览器,只允许 http://bb.aaa.com:9000 这个源请求服务器 $response->header('Access-Control-Allow-Origin', 'http://bb.aaa.com:9000'); // 告诉浏览器,请求头里只允许有这些内容 $response->header('Access-Control-Allow-Headers', 'Authorization, Content-Type, Depth, User-Agent, X-File-Size, X-Requested-With, X-Requested-By, If-Modified-Since, X-File-Name, X-File-Type, Cache-Control, Origin'); // 告诉浏览器,只允许暴露'Authorization, authenticated'这两个字段 $response->header('Access-Control-Expose-Headers', 'Authorization, authenticated'); // 告诉浏览器,只允许GET, POST, PATCH, PUT, OPTIONS方法跨域请求 $response->header('Access-Control-Allow-Methods', 'GET, POST, PATCH, PUT, OPTIONS'); // 预检 $response->header('Access-Control-Max-Age', 3600);
网页标题:详解vue或uni-app的跨域问题解决方案-创新互联
链接URL:http://ybzwz.com/article/eigos.html