首页 文章

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

提问于
浏览
2

我已经运行了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链接和div中添加'app'id和'example'组件)

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

2 回答

  • 0

    你需要运行:

    npm install
    

    然后 :

    npm run dev
    
  • 2

    最终我弄明白了会发生什么 . 我不知道为什么,但我得到了答案:

    您试图在非布局页面中包含vue组件,如 welcome.blade.php . 尝试在布局中包装此单个页面并添加组件,在本例中为 <example></example> . 请务必链接到 app.js .


    Updated :这正是发生的事情:Answer .

相关问题