【问题标题】:Vue in Laravel project doesn't appearLaravel 项目中的 Vue 没有出现
【发布时间】:2018-01-24 17:18:24
【问题描述】:

我开始使用 laravel 并尝试使用 Vue。所以在我的resources/assets/js/app.js 我有

Vue.component('example', require('./components/Example.vue'));
const app = new Vue({
   el: '#app'
});

所以我的 Example.vue 基本上是 laravel 提供的。在我的welcome.blad 我有

@extends('layouts.app')

@section('content')
    <example>
    </example>
@endsection
<script src="{{ elixir('js/app.js') }}"></script>

在我的 package.json 中有:

"devDependencies": {
    "vue": "^2.1.10",
    "vue-resource": "^1.0.3"
}

但是我的欢迎页面中没有出现任何内容。我跑了 npm install npm run dev 并在我的脚本中更改了一些东西,不记得所有但尝试了很多东西并且无法使其工作

【问题讨论】:

  • 检查控制台是否有错误。在您的布局中是否有 ID 为 app&lt;div&gt;
  • @ceejayoz 有,我不确定 example 必须在 de div 内部还是外部,但我都尝试了。 Uncaught TypeError: Cannot read property 'csrfToken' of undefined
  • 我会先修复那个位,然后看看是否有更多错误。有关 CSRF 令牌的详细信息,请参阅 laravel.com/docs/5.4/csrf
  • 很多 JS 错误会中断剩余 JS 的执行。控制台应始终是第一站。很高兴我能帮上忙!
  • @ceejayoz 你能给出一个正确的答案,以便我验证它并结束这个话题吗?如果你愿意,我可以自己做

标签: laravel vue.js


【解决方案1】:

Laravel 在 stock 模板中包含一些对 CSRF tokens 的默认处理。

Uncaught TypeError: Cannot read property 'csrfToken' of undefined

表示您已将其取出或以某种方式破坏它,从而阻止其余 JS 运行。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2021-11-23
    • 1970-01-01
    • 2020-07-18
    • 2020-05-29
    • 2016-11-28
    • 2020-01-30
    • 1970-01-01
    • 2018-10-05
    相关资源
    最近更新 更多