【问题标题】:In Vue, how do I bind a date object to a date input ? (v-model doesn't work)在 Vue 中,如何将日期对象绑定到日期输入? (v 模型不起作用)
【发布时间】:2018-04-01 09:52:26
【问题描述】:
// This doesn't work
<input type='date' v-model='store.myDateObject'>

如何将日期输入绑定到商店中的日期对象?

【问题讨论】:

    标签: vue.js


    【解决方案1】:

    假设您希望您的日期为午夜 UTC 日期对象,请执行此操作...

    <input type='date'
        :value='store.myDate.toJSON().substring(0,10)'
        @input='store.myDate = new Date($event.target.value)'
    >
    

    【讨论】:

    • 我不得不在 Vue 2.6.10、Chrome 73.0.3683.103 和 Edge 42.17134.1.0 的 @input 中使用 $event 而不是 $event.target.value。我不确定 Vue 本身或浏览器中的更改是否会导致此问题,但我不能说我有信心这将适用于每个浏览器。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2013-08-25
    • 1970-01-01
    • 2015-01-03
    • 1970-01-01
    • 2016-11-05
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多