Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

[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>
like image 696
silverFoxA Avatar asked Dec 31 '16 20:12

silverFoxA


2 Answers

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/

like image 70
Alexey Mezenin Avatar answered Oct 20 '22 14:10

Alexey Mezenin


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>
like image 4
Mandeep Kumar Avatar answered Oct 20 '22 15:10

Mandeep Kumar