axios添加自定义请求头
在axios拦截器中, headers[‘XXX’] = ‘XX’
配置后,thinkphp 返回跨域.需要对thinkphp中间件进行重新设置
主要配置在tp
-
复制 vendor\topthink\framework\src\think\middleware\AllowCrossDomain.php文件到app\common 下
-
追加vue传过来的自定义请求头到$header数组内Access-Control-Allow-Headers
protected $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, XXX',
];
- app\middleware.php引入
<?php
// 全局中间件定义文件
return [
\app\common\middleware\AllowCrossDomain::class
];