elementUI date-picker 日期格式转为 2023/08/08格式

      <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>
  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

你可能感兴趣的:(elementui,前端,javascript)