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

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

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

你可能感兴趣的:(vue.js,javascript,前端)