我有一个全新安装的laravel项目,所有组件都已更新。
我在welcome.blade.php文件中尝试添加app.js
,添加以下内容后出现此错误
[Vue警告]:找不到元素:#app
我遵循了这个帖子,但由于我的脚本位于页面底部,所以它不相关。 https://laracasts.com/discuss/channels/vue/fresh-laravel-setup-and-vue-2-wont-work
这是我的档案
<!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>
答案 0 :(得分:18)
答案 1 :(得分:2)
验证您的主设计文件app.blade.php包含一个div,其div的应用程序ID恰好在<body>
标记之后,如下所示:
<body>
<div id="app">
.
.
.
</div>
</body>
答案 2 :(得分:0)
有时候一切似乎都得到了,但是我们仍然遇到相同的错误,那么您必须复制此代码并粘贴到应用程序中。刀片。
<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>
答案 3 :(得分:0)
从脚本中删除推迟并在第
部分加载脚本示例
<script src="{{ asset('js/app.js') }}" defer></script> //Wrong
To
<script src="{{ asset('js/app.js') }}"></script> //Right
app.blade.php您的所有链接都加载到的主文件
<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>
<!--put your all script file here -->
<script src="{{ asset('js/app.js') }}"></script>
@yield('page-js-script')
</body>
home.blade.php文件或扩展主应用程序文件的子文件
@extends('layouts.app')
@section('content')
<div class="container">
.
.
.
.
.
.
</div>
@endsection
@section('page-js-script')
<script type="text/javascript">
$(document).ready(function() {
alert("Settings page was loaded");
});
</script>
@stop