2017-01-04 52 views
0

我想在我的項目中使用Laravel護照,我遵循Laravel護照https://laravel.com/docs/5.3/passport的本教程。要求未在app.js中爲laravel護照定義

繼本教程後,我得到Uncaught ReferenceError:require is not defined error。

請看看到我的文件:

  1. gulpfile.js

    var elixir = require('laravel-elixir'); 
    require('laravel-elixir-webpack'); 
    
    elixir(function(mix) { 
    
        mix.scripts('app.js'); 
    
        mix.styles([ 
           'bootstrap.min.css', 
           'font-awesome.min.css', 
           'gentelella.min.css' 
           ],'public/css/app.css'); 
    
    }); 
    
  2. 資源/資產/ JS/app.js

    Vue.component(
        'passport-clients', 
        require('./components/passport/Clients.vue') 
    ); 
    
    Vue.component(
        'passport-authorized-clients', 
        require('./components/passport/AuthorizedClients.vue') 
    ); 
    
    Vue.component(
        'passport-personal-access-tokens', 
        require('./components/passport/PersonalAccessTokens.vue') 
    ); 
    
    const app = new Vue({ 
        el: '#manage-passport' 
    }); 
    
  3. home.blade .php

    @extends('layouts.blank') 
    @section('content') 
    
    <div class="container" id="manage-passport"> 
    
        <!-- let people make clients --> 
        <passport-clients></passport-clients> 
    
        <!-- list of clients people have authorized to access our account --> 
        <passport-authorized-clients></passport-authorized-clients> 
    
        <!-- make it simple to generate a token right in the UI to play with --> 
        <passport-personal-access-tokens></passport-personal-access-tokens> 
    </div> 
    
    @stop 
    
  4. blank.blade.php

    <head> 
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> 
    
        <!-- Meta, title, CSS, favicons, etc. --> 
        <meta charset="utf-8"> 
        <meta http-equiv="X-UA-Compatible" content="IE=edge"> 
        <meta name="viewport" content="width=device-width, initial-scale=1"> 
    
        <title>Passport! | </title> 
    
        <meta name="token" id="token" value="{{ csrf_token() }}"> 
        <!-- Styles --> 
        <link href="/css/app.css" rel="stylesheet"> 
    
    </head> 
    
    <body class="nav-md"> 
        <div class="container body"> 
         <div class="main_container"> 
          @yield('content') 
         </div> 
        </div> 
    
        <script src="/js/jquery.min.js"></script> 
        <script src="/js/bootstrap.min.js"></script> 
        <script src="js/gentelella.min.js"></script> 
        <script type="text/javascript" src="//cdnjs.cloudflare.com/ajax/libs/toastr.js/latest/js/toastr.min.js"></script> 
        <link href="//cdnjs.cloudflare.com/ajax/libs/toastr.js/latest/css/toastr.min.css" rel="stylesheet"> 
        <script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/vue/1.0.26/vue.min.js"></script> 
        <script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/vue-resource/1.0.3/vue-resource.min.js"></script> 
        <script type="text/javascript" src="/js/app.js"></script> 
    
        @stack('scripts') 
    
    </body> 
    

+0

沒有ü更改後吞掉? –

+0

是的,但它顯示我的錯誤。 –

+0

你是怎麼吞下去的?好像你沒有吞嚥,否則你不會得到那個錯誤。 –

回答

-1

也許在沒有標記的問題呢?

blank.blade.php

<script> 
     window.Laravel = {!! json_encode(['csrfToken' => csrf_token()]) !!} 
</script> 

還,檢查是否傳輸參數,如令牌

Vue.http.interceptors.push((request, next) => { 
    request.headers.set('X-CSRF-TOKEN', Laravel.csrfToken); 

    next(); 
}); 
+0

仍然無法正常工作,顯示相同的錯誤。 –

+0

您在文件資源/資產/ js/app.js中顯示了所有代碼? – Alex

+0

是@Alex ...... –