在 vue.js 中格式化输入类型日期

Formatting input type date in vue.js

我用的是bootstrap-vue,里面有日期输入类型。

当我写一些数字时,默认格式是yyyyyy-mm-dd。

我想将该格式更改为 yyyy-mm-dd。

使用格式化程序:

:formatter="format"

在此函数中声明值的格式:

format(value, event) {
    return moment(value).format('YYYY-MM-DD')
}

作为使用 momentjs 库的示例。

试试这个:

<input type="date" v-model="moment(mydate).format('YYYY-MM-DD')" v-on:input="mydate = moment($event.target.value).toDate()"/>

我正在使用 moment.js

data:{
        startDate: moment().format("YYYY-MM-DD"),
        endDate: moment().format("YYYY-MM-DD"),
    }

HTML

<input type="date" class="form-control" v-model="startDate"> {{startDate}}
<input type="date" class="form-control" v-model="endDate"> {{endDate}}