javascript
<el-form-item label="基线日期:" prop="baselineDate">
<el-date-picker
type="date"
v-model="form.baselineDate"
placeholder="选择日期"
format="yyyy/MM/dd"
@change="(date, type) => changeTime(date, 'baselineDate')"
>
</el-date-picker>
</el-form-item>
<el-form-item label="对比日期:" prop="comparisonDate">
<el-date-picker
type="date"
v-model="form.comparisonDate"
placeholder="选择日期"
format="yyyy/MM/dd"
@change="(date, type) => changeTime(date, 'comparisonDate')"
>
</el-date-picker>
</el-form-item>
javascript
data() {
return {
form: {
baselineDate: "",
comparisonDate: "",
},
format: "yyyy/MM/DD",
};
},
methods:{
changeTime(date, type) {
console.log(date);
if (type == "comparisonDate") {
this.form.comparisonDate = moment(date).format(this.format);
} else {
this.form.baselineDate = moment(date).format(this.format);
}
},},
坑: dom 中 value注意这里的是 "yyyy/MM/dd" 。moment 中在 format格式化的时候是 "yyyy/MM/DD"。"YYYY/MM/DD"也可以
还是要仔细看官网:https://element.eleme.cn/#/zh-CN/component/date-picker#ri-qi-ge-shi