I've started to build vue.js app with Laravel using single-file components. The problem is with my app object: it is a DOM, not a Vue object and app won't work properly.
When I start my app, components are rendered properly, vue-devtools
recognizes Vue 2.2.6, evertything seems to work in the right way.
But when I type
console.log(app)
in chrome console I see a DOM object:
<div id="app"></div>
What more, when I try to change title property (and wanted to see changed hello
component on screen) just by typing
app.title = "awesomness"
in console, my component wouldn't change, but only my div#app
: (typed console.log(app)
<div id="app" title="awesomness"></div>
The question is: why? Samples below.
Test component Hello.vue
<template>
<div>
<p>{{ greeting }} World!</p>
</div>
<script>
module.exports = {
props: ['greeting'],
data: function() {
return {
}
}
}
</script>
<style scoped>
p {
color: red;
font-size: 20px;
}
</style>
part of my index/index view from laravel:
<div id="app">
<hello :greeting="title"></hello>
</div>
and finally my /resources/assets/js/app.js
file
import Vue from 'vue'
import Hello from './components/Hello.vue'
Vue.component('hello', Hello);
var app = new Vue({
el: '#app',
data: {
title: 'Hello Vue!',
todos: [
{ text: 'task 1' },
{ text: 'task 2' },
{ text: 'task 3' },
{ text: 'task 4' }
],
}
})