Vue + Thinkphp跨域,使用post无法请求的问题
Vue + Thinkphp跨域,使用post无法请求的问题
header('Access-Control-Allow-Origin:*'); // 响应类型 header('Access-Control-Allow-Methods:*'); // 响应头设置 header('Access-Control-Allow-Headers:x-requested-with,content-type');
namespace app\api\controller;
use think\Request;
header('Access-Control-Allow-Origin:*');
// 响应类型
header('Access-Control-Allow-Methods:*');
// 响应头设置
header('Access-Control-Allow-Headers:x-requested-with,content-type');
class user
class User extends Base
{
}
方法二:
路由部分处理:
Route::group('api', function () { Route::get('getlist', 'getList'); Route::post('postlist', 'postList'); })->prefix('api/')->allowCrossDomain([ 'Access-Control-Allow-Origin'=>'http://127.0.0.1:8011', 'Access-Control-Allow-Methods'=>'GET, POST, PATCH, PUT, DELETE', 'Access-Control-Allow-Headers' => '*', //是否允许后续请求携带认证信息(cookies),该值只能是true,否则不返回 'Access-Control-Allow-Credentials:true' ]);