简体   繁体   中英

[Vue warn]: Cannot find element: #app

I have a fresh installed laravel project with all the components updated.

All I did is tried to add app.js in my welcome.blade.php file, after adding the following I get this error

[Vue warn]: Cannot find element: #app

I followed this thread, but it's not relevant as my script is at the bottom of the page. https://laracasts.com/discuss/channels/vue/fresh-laravel-setup-and-vue-2-wont-work

Here's my file

    <!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">

    <title>{{$project}} | {{ $title }}</title>

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

    <!-- Styles -->
    <link href="/css/app.css" rel="stylesheet" type="text/css"/>

    <style>
      ...
    </style>
    </head>
    <body class="sticky-nav">
    <div id="nav">
    <div class="display-sm">
        <header class="top-header">
            <span class="menu-icon">☰</span>
        </header>
    </div>
        <div class="custom-container">
        <div id="logo" class="float-left">
            <img alt="xyz" src="/images/xyz.png"/><span> xyz</span>
        </div>
        <div id="btn-project" class="float-right">
            <a title="project" href="#" class="btn btn-project">Project</a>
        </div>
    </div>
    </div>
    <div class="sub-container">
    <h1 id="header-title">{{ $header_title }}</h1>
    <h2 id="meta-data"><i class="fa fa"></i>{{$location}} <span id="category"> <i></i>{{$category}} </span></h2>
    <div class="clear"></div>

    </div>
    <script src="/js/app.js"></script>
    <script>
    var wrap = $(".sticky-nav");

    wrap.on("scroll", function (e) {

        if (this.scrollTop > 147) {
            wrap.find('#nav').addClass("fix-nav");
        } else {
            wrap.find('#nav').removeClass("fix-nav");
        }

        });
    </script>
    </body>
    </html>

Error says it all. Vue can't find #app element, so you need to add it:

<div id='app'></div>

https://v2.vuejs.org/v2/guide/

Sometime everything seems got , but we are still getting same error then you have to copy this code and paste in app. blade.

<head>
<!-- Scripts -->
<script src="{{ asset('js/app.js') }}" defer></script>

<!-- Fonts -->
<link rel="dns-prefetch" href="//fonts.gstatic.com">
<link href="https://fonts.googleapis.com/css?family=Nunito" rel="stylesheet">

<!-- Styles -->
<link href="{{ asset('css/app.css') }}" rel="stylesheet">
</head>

<body>
<div id="app">
 .
 .
 .
 .
 .
 .
</div>
</body>

Verify that your main design file app.blade.php contains a div with the app id just after the <body> tag just like this:

<body>
    <div id="app">
    .
    .
    .
    </div>
</body>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM