element 中 datepicker設置,只能選中只能大於當前日期


1.只能選擇當前及以后的日期
<el-date-picker
       v-model="value1"
       type="date"
       :picker-options="pickerOptions">
</el-date-picker>

 data() {
        return {
            pickerOptions: {
                disabledDate(time) {
                    return time.getTime() < Date.now() - 8.64e7;
                }
            },
}

2.只能選擇今天以及今天以前的日期
  data (){
   return {
       pickerOptions: {
          disabledDate(time) {
            return time.getTime() > Date.now() - 8.64e6
          }
        }, 
   }    
}

3.只能選擇今天之后的日期

data (){
   return {
       pickerOptions: {
          disabledDate(time) {
            return time.getTime() < Date.now();
          }
        },  
   }     
}

4.只能選擇今天之前的日期
data (){
   return {
       pickerOptions0: {
          disabledDate(time) {
            return time.getTime() > Date.now();
          }
        },  
   }     
}

5.設置選擇三個月之前到今天的日期
data (){
   return {
       pickerOptions0: {
          disabledDate(time) {
            let curDate = (new Date()).getTime();
            let three = 90 * 24 * 3600 * 1000;
            let threeMonths = curDate - three;
            return time.getTime() > Date.now() || time.getTime() < threeMonths;;
          }
        }, 
   }    
}
組件代碼

<el-date-picker
       v-model="value1"
       type="date"
       placeholder="開始日期"
       :picker-options="pickerOptions0">
</el-date-picker>
<el-date-picker
       v-model="value2"
       type="date"
       placeholder="結束日期"
       :picker-options="pickerOptions1">
</el-date-picker>

情景1: 限制結束日期不能大於開始日期

data(){
    return {
         pickerOptions0: {
                disabledDate: (time) => {
                    if (this.value2 != "") {
                        return time.getTime() > Date.now() || time.getTime() > this.value2;
                    } else {
                        return time.getTime() > Date.now();
                    }
 
                }
            },
            pickerOptions1: {
                disabledDate: (time) => {
                    return time.getTime() < this.value1 || time.getTime() > Date.now();
                }
            },
    }     
}

原文:https://www.cnblogs.com/alice626/p/11424661.html


免責聲明!

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



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