【问题标题】:The specified value does not conform to the required format, "yyyy-MM-dd". Vue.js指定的值不符合要求的格式“yyyy-MM-dd”。 Vue.js
【发布时间】:2020-09-11 14:42:09
【问题描述】:

我正在尝试将当前记录日期放入我的input type="date" 字段。字符串完美地工作,当我单击按钮时,它们都会形成,日期除外。

我的输入类型是表格上的日期。我需要添加日期作为值。

这就是我目前正在尝试的方式:this.birth_date = student.birth_date;

但是日期是 Laravel 日期,我得到错误:指定的值“2000-07-08T00:00:00.000000Z”不符合要求的格式,“yyyy-MM-dd”。强>

我也尝试过用 moment.js 格式化日期,但这也没有用。

表格

<form @submit.prevent="addStudent()">
                <div class="form-group">
                    <input type="text" class="form-control" placeholder="First Name"  v-model="first_name">
                </div>
                <div class="form-group">
                    <input type="text" class="form-control" placeholder="Surname"  v-model="last_name">
                </div>
                <div class="form-group">
                    <input type="text" class="form-control" placeholder="Student Number" required v-model="student_number">
                </div>
                <div class="form-group">
                    <input type="text" class="form-control" placeholder="Phone Number" required v-model="phone_number">
                </div>
                <div class="form-group">
                    <input type="text" class="form-control" placeholder="E-Mail" required v-model="email">
                </div>
                <div class="form-group">
                    <input type="date" class="form-control" placeholder="Birth Date" :max="moment().format('YYYY-MM-DD')" required v-model="birth_date">
                </div>
                <div class="form-group">
                    <input type="text" class="form-control" placeholder="School Name" required v-model="school_name">
                </div>
                <button type="submit" class="btn btn-success">Save</button>
                <button @click="clearForm()" class="btn btn-info">Clear Form</button>
            </form>

请帮忙,谢谢!

【问题讨论】:

  • 请在后台显示html表单和验证
  • 我已将表单添加到问题中,我只在后端进行requiredmax:255 验证
  • 但我不认为这是后端的问题。它应该用选定的记录填充日期输入
  • 如何填写初始学生日期?
  • 请原谅,填充是什么意思?我对 Vue.js 很陌生,抱歉。

标签: javascript php laravel vue.js


【解决方案1】:

最好在发送到后端之前在 vue 代码中格式化输入日期值(birth_date)。

<input type="date" class="form-control" placeholder="Birth Date" required v-model="birth_date">

sumbit(){
    this.dateFormated = moment(birth_date).format('YYYY-MM-DD');
    //then you send dateFormated variable instead of birth_date
}

【讨论】:

    猜你喜欢
    • 2015-08-28
    • 2021-06-04
    • 2016-01-02
    • 1970-01-01
    • 2013-08-31
    • 2021-12-18
    相关资源
    最近更新 更多