I am creating a DOB Form.
I am using VueJS in the form. The user should their date of month first so that day is displayed according to the number of days in the respective month.
I am using filter()
and the problem is this
inside filter()
is undefined. How can I fix this?
new Vue ({
el: '.app',
data: {
months: [
{month: 'January', days: 31},
{month: 'February', days: 28},
{month: 'March', days: 31},
{month: 'April', days: 30},
{month: 'May', days: 31},
{month: 'June', days: 30},
{month: 'July', days: 31},
{month: 'August', days: 31},
{month: 'September', days: 30},
{month: 'October', days: 31},
{month: 'November', days: 30},
{month: 'December', days: 31},
],
selectedMonth: []
},
computed: {
filterDays() {
return this.months.filter(function(value) {
return value.month === this.selectedMonth;
});
}
},
});
<script src="https://cdnjs.cloudflare.com/ajax/libs/vue/2.5.16/vue.js"></script>
<div class="app">
<select id="dobd">
<option v-for="day in filterDays[0].days" :value="day">{{ day }}</option>
</select>
</div>
I know using a global variable might be the solution but I want to use selectedMonth
inside data()
due to my own needs.