3
// This doesn't work
<input type='date' v-model='store.myDateObject'>

How can I bind a date input to a date object in my store?

bbsimonbb
  • 27,056
  • 15
  • 80
  • 110

1 Answers1

5

Assuming you want your dates as midnight UTC date objects, do this...

<input type='date'
    :value='store.myDate.toJSON().substring(0,10)'
    @input='store.myDate = new Date($event.target.value)'
>
bbsimonbb
  • 27,056
  • 15
  • 80
  • 110
  • I had to use $event instead of $event.target.value in @input with Vue 2.6.10, Chrome 73.0.3683.103, and Edge 42.17134.1.0. I'm not sure if a change in Vue itself or in the browsers caused this, but I can't say I'm confident this will work in every browser. – Nate Bundy May 03 '19 at 17:35