Please help! I have 'undefined' props in child template.
Main js:
// some code before
window.Vue = require('vue');
import EventBus from '../components/event-bus';
// some code after
Vue.component('calendar-select', require('../components/admin/calendar_select.vue'));
const app = new Vue({
el: '#app',
data: function() {
return {
isActiveCalendar: true
}
},
methods: {
toggleCalendar() {
this.isActiveCalendar = !this.isActiveCalendar;
}
},
mounted() {
EventBus.$on('toggleCalendar', this.toggleCalendar);
}
});
After this I created template like this:
<template>
<div class="custom-select" v-bind:class="{ active: isActiveCalendar}" >
<div class="box flex" v-on:click="toggleCalendar" >
<span>Calendar</span>
<img src="/assets/img/admin/arrow-down.png" alt="#">
</div>
</div>
</div>
</template>
<script>
import EventBus from '../event-bus';
export default
{
// ------- start
props: ['isActiveCalendar'],
data: function() {
return {
}
},
methods: {
toggleCalendar: function(event) {
console.log(this.isActiveCalendar)
EventBus.$emit('toggleCalendar');
}
}
// ------- end
}
</script>
When I do console.log on this.isActiveCalendar, the variable is undefined and in Vue plugin for Chrome is same thing.
Please, tell me, what mistake I am doing!
Thanks!
As stated in the documentation for passing props.
HTML attributes are case-insensitive, so when using non-string templates, camelCased prop names need to use their kebab-case (hyphen-delimited) equivalents:
In this example you would need to use
<calendar-select v-bind:is-active-calendar="isActiveCalendar"></calendar-select>
so that it would pass the value of the variable into the prop.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With