简体   繁体   English

如何对日期类型的输入进行 v-model

[英]How to v-model a input of type date

I have an input like so:我有这样的输入:

<input class="input" type="date" v-model="dob" />

dob is initialized as null, and works properly. dob初始化为null,工作正常。 For example 03/05/2006 models to 2006-03-05T00:00:00.000+00:0 .例如 03/05/2006 模型到2006-03-05T00:00:00.000+00:0 However when dob is inititialized as 2006-03-05T00:00:00.000+00:0 , it doesn't show in the date input.但是,当dob初始化为2006-03-05T00:00:00.000+00:0时,它不会显示在日期输入中。 How would I fix this.我将如何解决这个问题。

EDIT: you could use to set a default value and have it changing afterwards.编辑:您可以使用设置默认值并在之后更改它。

data() {
  return {
    initialDate: Date.now(),
  };
},
computed: {
  dob: {
    get() {
      return this.initialDate;
    },
    set(newValue) {
      this.initialDate = newValue;
    },
  },
},

Where is your input coming from?你的输入来自哪里? It probably needs a UNIX timestamp like 1612454883231 .它可能需要一个 UNIX 时间戳,如1612454883231 Try initializing it with Date.now() or maybe try new Date().toISOString().slice(0,10) .尝试使用Date.now()初始化它,或者尝试使用new Date().toISOString().slice(0,10)
Also, new Date('2006-03-05T00:00:00') if you want to set it manually (and since it's a date of birth...).此外,如果您想手动设置它(并且因为它是出生日期......),请使用new Date('2006-03-05T00:00:00') ) 。

If it doesn't work, you need to dig the documentation to see which format it accepts.如果它不起作用,您需要挖掘文档以查看它接受哪种格式。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM