el-date-picker如果超过限制跨度则提示

需求:实现日期时间选择组件跨度如果超过限制天数,点击查询则提示超过限制时间

el-date-picker如果超过限制跨度则提示_第1张图片

封装一个方法,传入开始和结束时间以及限制天数,如果超过则返回false

//计算时间跨度是否超过限制天数
    isTimeSpanWithinLimit(startTime, endTime, limitDays) {
      const startDateTime = new Date(startTime)
      const endDateTime = new Date(endTime)
      const timeDifference = endDateTime - startDateTime
      const daysDifference = Math.floor(timeDifference / (1000 * 60 * 60 * 24))
      return daysDifference <= limitDays
    }

你可能感兴趣的:(vue.js,javascript,ecmascript,elementui)