传参就会跨域。
laravel想解决跨域问题,需要动好几个页面。
thinkPHP6就简单多了。
Route::get('/xxx/xxx/:id', 'xxxx')
->allowCrossDomain([
'Access-Control-Allow-Origin'=> 'http://域名地址',
'Access-Control-Allow-Credentials'=> 'true'
]);
Route::group('/h5', function(){
Route::get('/xxx/xxx/:id', 'xxxx');
})->prefix('app\Controller\H5\Api/')->allowCrossDomain([
'Access-Control-Allow-Origin'=> 'http://域名地址',
'Access-Control-Allow-Credentials'=> 'true'
]);
Route::group('/h5', function(){
Route::get('/xxx/xxx/:id', 'xxxx');
})->prefix('app\Controller\H5\Api/')->allowCrossDomain([
'Access-Control-Allow-Origin'=> 'http://域名1',
'Access-Control-Allow-Credentials' => 'true'
]);
Route::group('/h5', function(){
Route::get('/xxx/xxx/:id', 'xxxx');
})->prefix('app\Controller\H5\Api/')->allowCrossDomain([
'Access-Control-Allow-Origin' => 'http://域名2',
'Access-Control-Allow-Credentials'=> 'true'
]);
allowCrossDomain()也可以不传数组直接使用,这样就不是针对某个域名了,而是全局解除限制。