【问题标题】:Cannot setup and run vuejs in laravel无法在 laravel 中设置和运行 vuejs
【发布时间】:2016-10-01 09:24:10
【问题描述】:

我对 vue.js 很陌生,但对 laravel 很熟悉。现在有了 laravel 5.3 版本,我正在尝试使用 vue 运行一些示例应用程序。

资源/js/app.js:

    /**
     * First we will load all of this project's JavaScript dependencies which
     * include Vue and Vue Resource. This gives a great starting point for
     * building robust, powerful web applications using Vue and Laravel.
     */

    require('./bootstrap');

    /**
     * Next, we will create a fresh Vue application instance and attach it to
     * the body of the page. From here, you may begin adding components to
     * the application, or feel free to tweak this setup for your needs.
     */



    new Vue({
          el: 'body',
          data: {
          message: 'Hello Vue World!'
          }
        })

welcome.blade.php

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">
<script src="{{ elixir('js/app.js') }}"></script>
<link rel="stylesheet" href="{{ elixir('css/app.css') }}">
<title>Laravel</title>

<!-- Fonts -->
<link href="https://fonts.googleapis.com/css?family=Raleway:100,600"
    rel="stylesheet" type="text/css">


</head>
<body>
    <div id="app">@{{ message }}</div>
</body>
</html>

gulpfile.js

const elixir = require('laravel-elixir');

require('laravel-elixir-vue');

/*
 |--------------------------------------------------------------------------
 | Elixir Asset Management
 |--------------------------------------------------------------------------
 |
 | Elixir provides a clean, fluent API for defining some basic Gulp tasks
 | for your Laravel application. By default, we are compiling the Sass
 | file for our application, as well as publishing vendor resources.
 |
 */

elixir(function(mix) {
    mix.sass('app.scss');
});

elixir(function(mix) {
    mix.browserify('app.js');
});

elixir(function(mix) {
    mix.version(['css/app.css', 'js/app.js']);
});

我收到一条错误消息[Vue warn]: Cannot find element: body

感谢任何帮助,

当我运行它时,我只看到 {{message}},而不是 Hello Vue World。

在这里学习了一些教程:https://asked.io/quick-start-guide--laravel-5--vue-js---bootstrap-3

【问题讨论】:

    标签: javascript php laravel-5 vue.js


    【解决方案1】:

    尝试将脚本标签放在正文的末尾而不是头部。
    当脚本在 head-tag 中加载时,body 还不存在。

    【讨论】:

      猜你喜欢
      • 2020-09-19
      • 2017-05-03
      • 2020-08-05
      • 2018-08-17
      • 1970-01-01
      • 2020-05-26
      • 2015-05-20
      • 2020-06-26
      相关资源
      最近更新 更多