想要的效果:
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>