laravel - 如何在 Laravel 5.4 中加载 Vue 组件?

标签 laravel vue.js components vuejs2 laravel-5.4

我已运行 npm run watch 并收到消息

This dependency was not found:

*  in ./resources/assets/js/app.js

To install it, you can run: npm install --save 

所以我运行了 npm install --save 但仍然收到相同的消息。

根据我的理解,我需要 npm run 或 npm run watch 来加载 Laravel 中的 Vue 文件。

例如,在“resources/assets/js/components/Example.vue”文件中,我对其进行了编辑,但是当我加载“resources/views/welcome.blade.php”文件时,我的文件如下,Example.vue 文件的更新不会加载。

<!DOCTYPE html>
<html lang="{{ config('app.locale') }}">
    <head>
        <meta charset="utf-8">
        <meta http-equiv="X-UA-Compatible" content="IE=edge">
        <meta name="viewport" content="width=device-width, initial-scale=1">

        <title>Laravel</title>

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

        <!-- Styles -->
        <style>
            html, body {
                background-color: #fff;
                color: #636b6f;
                font-family: 'Raleway', sans-serif;
                font-weight: 100;
                height: 100vh;
                margin: 0;
            }

            .full-height {
                height: 100vh;
            }

            .flex-center {
                align-items: center;
                display: flex;
                justify-content: center;
            }

            .position-ref {
                position: relative;
            }

            .top-right {
                position: absolute;
                right: 10px;
                top: 18px;
            }

            .content {
                text-align: center;
            }

            .title {
                font-size: 84px;
            }

            .links > a {
                color: #636b6f;
                padding: 0 25px;
                font-size: 12px;
                font-weight: 600;
                letter-spacing: .1rem;
                text-decoration: none;
                text-transform: uppercase;
            }

            .m-b-md {
                margin-bottom: 30px;
            }
        </style>
    </head>
    <body>
        <div class="flex-center position-ref full-height">
            @if (Route::has('login'))
                <div class="top-right links">
                    @if (Auth::check())
                        <a href="{{ url('/home') }}">Home</a>
                    @else
                        <a href="{{ url('/login') }}">Login</a>
                        <a href="{{ url('/register') }}">Register</a>
                    @endif
                </div>
            @endif

              <div id="app">
                <example></example>
              </div>

            <div class="content">
                <div class="title m-b-md">
                    Laravel
                </div>

                <div class="links">
                    <a href="https://laravel.com/docs">Documentation</a>
                    <a href="https://laracasts.com">Laracasts</a>
                    <a href="https://laravel-news.com">News</a>
                    <a href="https://forge.laravel.com">Forge</a>
                    <a href="https://github.com/laravel/laravel">GitHub</a>
                </div>
            </div>
        </div>


        <script src='js/app.js'></script>
    </body>
</html>

(我只在脚本 src 链接和带有“app”id 和“example”组件的 div 中添加)

我必须做什么才能加载对Example.vue 文件所做的更改?之后,我还需要在 Laravel 的 Vue.js 中为我的应用程序创建新组件。

最佳答案

您需要运行:

npm install

然后:

npm run dev 

关于laravel - 如何在 Laravel 5.4 中加载 Vue 组件?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43311010/

相关文章:

javascript - 即使在脚本之前包含 app.js 之后,jquery 也无法正常工作

php - 检索多对多关系。拉维尔

php - 即使事件被触发,Laravel Listener 也没有被触发

javascript - 使用vuejs隐藏和显示后jquery方法停止工作

vue.js - [Vue路由器警告] : No match found for location with path

javascript - 使用 .NET (MVC) 的模板实现 (VUE) 问题

vue.js - Vue组件保存数据供以后使用

laravel - 存储方法无法使用资源路由

javascript - React js 使用 json 响应渲染功能性 html

actionscript-3 - 如何在 Flash Professional 中为 Flash Stage 实例提供唯一属性以传递给 AS3 脚本?