el-date-picker 最长时间跨度为15天且最小于当前时间

2023-12-14 11:47:49
  <el-date-picker
     size="small"
     v-model="searchDate"
     type="daterange"
     clearable
     range-separator="至"
     start-placeholder="开始日期"
     end-placeholder="结束日期"
     value-format="yyyy-MM-dd"
     :picker-options="pickerOptions">
  </el-date-picker>

let choiceDate = null;
pickerOptions: {
   onPick: ({ maxDate, minDate }) => {
      this.choiceDate = minDate.getTime();
      if (maxDate && maxDate.getTime() > new Date().getTime()) {
           this.choiceDate = "";
      } 
   },
   disabledDate: (time) => {
      const today = Date.now();
      if (this.choiceDate) {
          const range = 14 * 24 * 3600 * 1000;
          let minTime = this.choiceDate - range;
          let maxTime = this.choiceDate + range;
          maxTime = maxTime > today ? today : maxTime;
          return time.getTime() < minTime || time.getTime() > maxTime;
      }
      return time.getTime() > today;
}

文章来源:https://blog.csdn.net/fanlc8888/article/details/134989312
本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。