求助:Laravel + vue 刚搭好环境就出错。谁能帮我下?
错误:
created
[Vue warn]: Cannot find element: .a
Component mounted.
ready
view页面:
<!DOCTYPE html>
<html>
<head>
<script>
window.Laravel = {!! json_encode([
'csrfToken' => csrf_token(),
]) !!};
</script>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">
<meta name="X-CSRF-TOKEN" content="{{csrf_token()}}">
<title>Laravel</title>
<link rel="stylesheet" href="{{asset('public/css/app.css')}}">
<script type="text/javascript" src="{{asset('public/js/app.js')}}"></script>
</head>
<body>
<div class="a">
<example></example>
</div>
</body>
</html>
app.js
require('./bootstrap');
import Vue from 'vue'
import Example from './components/Example.vue'
const app = new Vue({
el: '.a',
render: h => h(Example),
created: function () {
console.log('created');
},
mounted: function(){
console.log('ready');
}
});
<div class=".a">
改成<div class="a">
多学点基础知识吧,还没学会走路就想跑了
多谢,多谢,但是改了还是不行哦。之前我是用 id="app",它就报错,找不到 #app了。
哈哈, 解决了。是顺序的问题,要在页面加载之后放Vue,把
<script type="text/javascript" src="{{asset('public/js/app.js')}}"></script>
放在最后就是了。多谢多谢。