1、禁止选择今年之前的所有年份
<el-date-pickerv-if="tabsActive === 0":clearable="false"v-model="yearValue"@change="yearTimeChange"type="year"placeholder="选择年"value-format="yyyy":picker-options="pickerOptions"style="width: 90px; border-radius: 8px"></el-date-picker>data () {return {pickerOptions: {disabledDate (time) {return time.getFullYear() < new Date().getFullYear()}},}}
2、禁止选择今天之前的所有日期
<el-date-picker:clearable="false"style="width: 90px; border-radius: 8px"v-model="expiration"type="date"value-format="yyyy-MM-dd"placeholder="选择日期":picker-options="pickerOptions2"@change="getReceivableFun"></el-date-picker>data () {return {pickerOptions2: {disabledDate (time) {return time.getTime() < new Date().getTime() - 86400000 // - 86400000是否包括当天}},}}
3、选择时间限制 当选择第一个时间后 前后范围限制18个月
<el-date-pickerstyle="width: 230px"v-model="countryTime"type="monthrange"range-separator="至"start-placeholder="开始月份"end-placeholder="结束月份"value-format="yyyy-MM"size="small":clearable="false":picker-options="pickerOptions"@change="monthrangeChange($event, 1)"></el-date-picker>data () {return {minDate: null,maxDate: null,pickerOptions: {disabledDate: (time) => {if (this.minDate !== null && this.maxDate === null) {let minMonth = this.minDate.getMonth(),lastYear = new Date(this.minDate).setMonth(minMonth - 17),nextYear = new Date(this.minDate).setMonth(minMonth + 17)// 只能选 minDate 前后18个月的范围return time.valueOf() < lastYear.valueOf() || time.valueOf() > nextYear.valueOf()}return false},onPick: ({ minDate, maxDate }) => {this.minDate = minDatethis.maxDate = maxDate}},}}
4、禁止选择指定日期之前的所有日期
data(){return{deadlineTime:'2023-11-20' // 代表指定日期pickerOptions: {disabledDate(v) {return v.getTime() < new Date(deadlineTime || new Date()).getTime(); },},}
}