## 如何跨域 跨域只需在 [前置中间件](https://github.com/mix-php/mix/blob/master/applications/http/src/Middleware/BeforeMiddleware.php) 增加跨域的代码,如下: ~~~ // 跨域设置 $origin = app()->request->header('origin'); $allowOrigin = [ 'http://www.test.com', 'http://www.test1.com', ]; if (in_array($origin, $allowOrigin)) { app()->response->setHeader('Access-Control-Allow-Origin', $origin); app()->response->setHeader('Access-Control-Allow-Headers', 'Origin, X-Requested-With, Content-Type, Accept, Authorization'); app()->response->setHeader('Access-Control-Allow-Methods', 'GET, POST, PUT, DELETE, OPTIONS, PATCH'); } if (app()->request->isOptions()) { return ''; } ~~~ - Access-Control-Allow-Origin:允许跨域的域名 - Access-Control-Allow-Headers:允许跨域的请求头 - Access-Control-Allow-Methods:允许跨域的请求方法