element-ui學習之-------el-date-picker設置選擇間隔時間不能超過15天


想要的效果:

data() {
  return {
  choiceDate0: "",
  pickerOptions: {
    // 設置不能選擇的日期
    onPick: ({
      maxDate,
      minDate
    }) => {
      if (minDate) { //如果默認有最小日期
        this.choiceDate0 = minDate.getTime();
      } else { //如果最小日期被清空,則最小日期為當天
        this.choiceDate0 = new Date();
      }
      if (maxDate) {
        this.choiceDate0 = '';
      }
    },
    disabledDate: (time) => {
      let choiceDateTime = new Date(this.choiceDate0).getTime(); //選中的第一個日期
      if (this.choiceDate0) {
        //間隔15天,則加減14天---“這主要看需求”
        //14天的時間戳:14*24*3600*1000=1209600000
        return (time.getTime() > (choiceDateTime + 1209600000))||(time.getTime() < (choiceDateTime-1209600000));
      }
    }
  },
  };
},

注意:不可選日期兩個條件之間要用 “||【或】”  隔開,不能用“&&【與】”

<el-date-picker v-model="dateRange" type="daterange" range-separator="至"
start-placeholder="開始日期" end-placeholder="結束日期" :picker-options="pickerOptions">
</el-date-picker>

  

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM