javascript - 无法在 laravel 中设置和运行 vuejs

标签 javascript php laravel-5 vue.js

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

resources/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

最佳答案

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

关于javascript - 无法在 laravel 中设置和运行 vuejs,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39804964/

相关文章:

javascript - 在 Tizen webapp 上使用 Jquery mobile

php - Telegram 上的内联键盘用于发送到 channel

mysql - 如何从 Laravel 中的连接查询中选择特定模型

mysql - Laravel 数据库 MySQL 查询需要很长时间

javascript - Protractor 无法单击与 $timeout 关联的链接

javascript - 我如何在 vue 模板中使用 const?

php - 我有一个表图像和 album_images。 album_images 表是不必要的吗?

PHP 正则表达式从字符串 Markdown

laravel-5 - 如何更改 Laravel 中的列名称?

javascript - 第一次异常后继续测试 | Chai | Mocha