I want to be able to bind a class to my component template based on a condition but also apply a default class that is always there.
Here's my code so far I'm able to get it to apply the currentMonth class when the condition is met but not the event_month class never gets applied. Am I using the correct syntax?
const listTemplate = '' +
'<div class="list_body">' +
'<div v-for="(month, index) in months" v-bind:class="[event_month, {current : index === currentMonth}]">' +
'{{month}}' +
'</div>' +
'</div>';
Vue.component('events-list-view', {
template: listTemplate,
data() {
return {
months: ['January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December'],
currentMonth: new Date().getMonth(),
};
},
});
new Vue({ el: "#app" });
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/vue/2.5.17/vue.js"></script>
<div id="app">
<events-list-view />
</div>