laravel - Vue.js + Laravel5.7 'Hello World' 测试不起作用

标签 laravel vue.js npm

我想要渲染 Vue.js 代码,但无法在 LARAVEL 5.7 中工作

我的app.js代码:

require('./bootstrap');

window.Vue = require('vue');

Vue.component('hello-world-component', require('./components/HelloWorld.vue'));

const app = new Vue({
    el: '#app'
});

和新文件 HelloWorld.vue :

<template>
  <div class="container">
    Hello Laravel + Vue!
  </div>
</template>

<script>
  export default {
    mounted() {
      console.log('Component mounted.')
    }
  }
</script>

还有welcome.blade.php:

<!doctype html>
<html>
    <head>
        <meta charset="utf-8">
        <meta name="viewport" content="width=device-width, initial-scale=1">
        <meta name="csrf-token" content="{{ csrf_token() }}">
        <title>Laravel</title>
    </head>
    <body>
        <div class="content">
            <div class="title m-b-md">
                <hello-world-component></hello-world-component>
            </div>
        </div>
    </body>
</html>

当我运行这个命令时,

sudo npm run dev

结果:

DONE  Compiled successfully in 6224ms                                                                   7:16:51 AM
       Asset     Size  Chunks                    Chunk Names
  /js/app.js  1.38 MB       0  [emitted]  [big]  /js/app
/css/app.css   198 kB       0  [emitted]         /js/app

但是当我连接索引页面时,没有显示我的 HelloWorld.Vue 代码。

我不知道出了什么问题?

最佳答案

您需要一个 id 为 app 的元素来挂载。例如:

html

<body>
    <div id="app"></div>
</body>
<script src="/js/app.js"></script>

js

const app = new Vue({
  el: '#app',
  template: '<hello-world-component></hello-world-component>'
});

关于laravel - Vue.js + Laravel5.7 'Hello World' 测试不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53533820/

相关文章:

linux - Apache 不会监听除端口 80 以外的其他端口

javascript - 动态定义页面方向 - Vue Js

javascript - Storybook:如何根据全局变量更新 i18 语言环境

javascript - Vue.js中如何获取组件元素的offsetHeight?

laravel - 宅基地的多个文件夹不同步

php - 调用未定义的方法 Illuminate\\Database\\Schema\\Blueprint::increments()

javascript - Node.js模块的动态安装和加载

firebase - 使用 npm 安装 firebase 时,gyp 和 node-pre-gyp 失败

php - Laravel 5.4 是否已完成记录作业的解决方案?

angular - Sweetalert 没有运行,我的 TS 文件出错