Reputation: 67
I am trying to get the current month in an input type month in vue.js, but I have no clue how, does anybody have a clue please?
HTML:
<input type="month" v-model="month">
JS:
data()
{
return{
date: new Date().toISOString().slice(0,10)
};
},
Upvotes: 0
Views: 1374
Reputation: 460
Your v-model
attribute on your input
element is not referencing your date
data property. It does not know where to bind its input value:
<input type="month" v-model="date">
From the docs:
You can use the v-model directive to create two-way data bindings on form input, textarea, and select elements. It automatically picks the correct way to update the element based on the input type.
Upvotes: 1
Reputation: 67
I got the problem, the slice was not doing the right amount it should be:
new Date().toISOString().substr(0,7)
instead of
new Date().toISOString().substr(0,10)
Upvotes: 1