这个错误是因为startDateendDate的值不是有效的Date对象造成的。可能是this.form.startAccountingTimethis.form.endAccountingTime的值不是有效的日期字符串。

你可以在调用new Date()之前,先打印一下this.form.startAccountingTimethis.form.endAccountingTime的值,确保它们是有效的日期字符串。如果不是,你需要检查你的数据源,确保它们是正确的日期格式。

另外,你还可以使用moment.js库来处理日期和时间,它提供了更方便和灵活的日期操作方法。你可以先将日期字符串转换为moment对象,然后再进行比较。

例如:

import moment from 'moment';

// ...

checkDateOrder(rule, value, callback) {
  if (this.form.startAccountingTime && this.form.endAccountingTime) {
    const startDate = moment(this.form.startAccountingTime, 'YYYY-MM-DD');
    const endDate = moment(this.form.endAccountingTime, 'YYYY-MM-DD');
    
    if (startDate.isAfter(endDate)) {
      callback(new Error('起始日期不能晚于结束日期'));
    } else {
      callback();
    }
  } else {
    callback();
  }
},

这样可以确保你的日期比较逻辑正常工作。

解决Element UI表单校验中`el.form.blur`事件报错:'TypeError: dateObject.getTime is not a function'

原文地址: http://www.cveoy.top/t/topic/qx9b 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录