關於 vue Laravel5.5 前後段分離式開發介面跨域問題請教

zhangjinlong發表於2018-10-03
    首次接觸laravel很想寫點什麼學習,購買了laravel web入門之後開始學習接觸這個框架,做分離式開發,
    !後端簡單業務邏輯已經完成但是前端vue介面請求一直報錯跨域問題,
    **找遍度娘發現都引用擴充套件laravel-cors對應的配置都已經完成配置但是vue介面請求還是報錯跨域**!
    首次接觸這個框架還請各位大神不吝賜教!話不多說貼圖上來:

    ## app.php 檔案
    `   /*
     * Application Service Providers...
     */
    App\Providers\AppServiceProvider::class,
    App\Providers\AuthServiceProvider::class,
    // App\Providers\BroadcastServiceProvider::class,
    App\Providers\EventServiceProvider::class,
    App\Providers\RouteServiceProvider::class,
    Barryvdh\Cors\ServiceProvider::class,

`

##Knernl.php檔案
    `protected $middleware = [
    \Illuminate\Foundation\Http\Middleware\CheckForMaintenanceMode::class,
    \Illuminate\Foundation\Http\Middleware\ValidatePostSize::class,
    \App\Http\Middleware\TrimStrings::class,
    \Illuminate\Foundation\Http\Middleware\ConvertEmptyStringsToNull::class,
    \App\Http\Middleware\TrustProxies::class,
    \Barryvdh\Cors\HandleCors::class,
];`

## cors.php檔案
`return [

/*
|--------------------------------------------------------------------------
| Laravel CORS
|--------------------------------------------------------------------------
|
| allowedOrigins, allowedHeaders and allowedMethods can be set to array('*')
| to accept any value.
|
*/

'supportsCredentials' => false,
'allowedOrigins' => ['*'],
'allowedOriginsPatterns' => [],
'allowedHeaders' => ['*'],
'allowedMethods' => ['*'],
'exposedHeaders' => [],
'maxAge' => 0,

];
`

以前使用的tp框架哎都是從核心載入層直接設定跨域請求配置,目前才接觸這個框架所以還望解答謝謝!

本作品採用《CC 協議》,轉載必須註明作者和本文連結

相關文章