Currently I'm using Laravel 5.2 with Elixir 5 and Vue 2.0.
I'm stuck on how to access and imported component's data from the element view using something like v-if.
Here's my setup:
resources\views\vuetest.blade.php
<div id="app">
<modal v-if="showModal"></modal>
<button>Show Modal</button>
</div>
resources\assets\vuejs\app.js
import Vue from 'vue';
import Modal from './components/modals/show-modal.vue';
Vue.component('modal', Modal);
if (document.getElementById("app")){
var app = new Vue({
el: '#app',
data: {
},
methods: {
},
computed: {
},
components: {
'modal': Modal
}
});
window.vue = app;
}
resources\assets\vuejs\components\modals\show-modal.vue
<template>
<div id="myModal" class="modal fade" role="dialog">
<div class="modal-dialog">
<!-- Modal content-->
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal">×</button>
<h4 class="modal-title">Modal Header</h4>
</div>
<div class="modal-body">
<p>Some text in the modal.</p>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
</div>
</div>
</template>
<script>
export default {
data() {
return {
showModal: false
}
},
components: {
},
}
</script>
Now if I just use this without v-if then it works and pulls in the template correctly.
However if I use what I had in my example it gives me an error:
app.js:967 [Vue warn]: Property or method "showModal" is not defined on the instance but referenced during render. Make sure to declare reactive data properties in the data option.
(found in <Root>)
If I add data in main app.js it can access it but not in imported child components. I'd rather not make the main app.js messy and better to use imports and keep components in organized subfolders. How can I access these child component data properly?