我有一个 Vuetify 日期选择器:
<v-menu
v-model="menu1"
:close-on-content-click="false"
max-width="290"
>
<template v-slot:activator="{ on }">
<v-text-field
v-model="editedItem.Eintrittsdatum"
clearable
color="primary"
label="Eintrittsdatum"
v-on="on"
></v-text-field>
</template>
<v-date-picker
v-model="editedItem.Eintrittsdatum"
@change="menu1 = false"
locale="de"
></v-date-picker>
</v-menu>
Run Code Online (Sandbox Code Playgroud)
返回值是正常格式的日期 (yyyy-mm-dd)。这也是我想保存在 v-model 中的数据(并最终保存在数据对象中)。但是,只是为了吸引眼球,我想以不同的格式显示文本字段的值。
我创建了一个小函数:
formatDate(date) {
return date ? moment(date).format("L") : "";
}
Run Code Online (Sandbox Code Playgroud)
有没有办法调用这个函数来覆盖显示的值?
将 formatDate 更改为计算的,并利用您已经定义的editedItem.Eintrittsdatum,它用于v-model您的实际v-date-picker
在您的脚本标签中:
computed: {
formatDate() {
return this.editedItem.Eintrittsdatum
? moment(this.editedItem.Eintrittsdatum).format("L")
: "";
}
}
Run Code Online (Sandbox Code Playgroud)
改变了 v-text-field
<v-text-field
:value="formatDate"
clearable
color="primary"
label="Eintrittsdatum"
v-on="on"
></v-text-field>
Run Code Online (Sandbox Code Playgroud)
工作沙箱:https : //codesandbox.io/s/vuetify-playground-y7ziz
| 归档时间: |
|
| 查看次数: |
4479 次 |
| 最近记录: |