简体   繁体   English

在laravel护照的app.js中未定义require

[英]require is not defined in app.js for laravel passport

I want to use Laravel Passport in my project, I have followed this tutorial of Laravel Passport https://laravel.com/docs/5.3/passport . 我想在我的项目中使用Laravel Passport,我遵循了Laravel Passport的教程https://laravel.com/docs/5.3/passport

After following this tutorial, I am getting Uncaught ReferenceError: require is not defined error. 在学习本教程之后,我遇到了Uncaught ReferenceError:require未定义错误。

Please have a look into my files : 请查看我的文件:

  1. gulpfile.js 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. resource/assets/js/app.js 资源/资产/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 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 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> 

Maybe the problem in the absence of token? 也许没有令牌的问题?

blank.blade.php blank.blade.php

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

also, check whether the transmitted parameters such as token 另外,检查是否传输了令牌等参数

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

    next();
});

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM