thinkphp6.0前后端分离跨域处理
- 建立一个跨域中间键CrossDomain.php (tp6现在跨域中间键有点问题)

- 中间键内代码CrossDomain.php
<?php
namespace app\middleware;
use think\Response;
class CrossDomain
{
public function handle($request, \Closure $next)
{
header('Access-Control-Allow-Origin: *');
header('Access-Control-Max-Age: 1800');
header('Access-Control-Allow-Methods: GET, POST, PATCH, PUT, DELETE');
header('Access-Control-Allow-Headers: Authorization, Content-Type, If-Match, If-Modified-Since, If-None-Match, If-Unmodified-Since, X-CSRF-TOKEN, X-Requested-With, Token');
if (strtoupper($request->method()) == "OPTIONS") {
return Response::create()->send();
}
return $next($request);
}
}
- 自动引用

