AI智能
改变未来

Laravel Framework 6框架配置前后端分离之后的跨域问题

2020年8月10日19:41:08

1、跨域问题,报错如下

新建中间件

代码如下

[code]<?phpnamespace App\\Http\\Middleware;use Closure;class CorsMiddleware{/*** Handle an incoming request.** @param \\Illuminate\\Http\\Request $request* @param \\Closure $next* @return mixed*/public function handle($request, Closure $next){return $next($request)->header(\'Access-Control-Allow-Origin\', \'*\')->header(\'Access-Control-Allow-Methods\', \'POST, GET, OPTIONS, PUT, DELETE\')->header(\'Access-Control-Allow-Headers\', \'Content-Type, Accept, Authorization, X-    Requested-With\');}}

使用如下:

[code]\'cors\' => \\App\\Http\\Middleware\\CorsMiddleware::class,

 

赞(0) 打赏
未经允许不得转载:爱站程序员基地 » Laravel Framework 6框架配置前后端分离之后的跨域问题