elementui el-date-picker禁止选择今年、今天、之前、时间范围限制18个月

1、禁止选择今年之前的所有年份

javascript 复制代码
          <el-date-picker
            v-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**、禁止选择今天之前的所有日期**

javascript 复制代码
          <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个月**

javascript 复制代码
          <el-date-picker
              style="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 = minDate
          this.maxDate = maxDate
        }
      },
    }
  }

            

4、禁止选择指定日期之前的所有日期

javascript 复制代码
 
data(){
  return{
    deadlineTime:'2023-11-20'  //  代表指定日期
    pickerOptions: {
        disabledDate(v) {
          return v.getTime() < new Date(deadlineTime || new Date()).getTime(); 
        },
      },
  }
}
相关推荐
tager5 小时前
🔥3行代码搞定全局代理!告别插件依赖的极简方案
前端·fiddler·charles
gnip6 小时前
axios 拦截器实现用户无感刷新 access_token
前端
程序员码歌6 小时前
【零代码AI编程实战】AI灯塔导航-成果展示篇
前端·ai编程·cursor
gnip6 小时前
前端实现即时通讯,常用的技术
前端
烛阴7 小时前
告别 any!用联合类型打造更灵活、更安全的 TS 代码
前端·typescript
excel8 小时前
全面解析 JavaScript 类继承:方式、优缺点与应用场景
前端
用户21411832636028 小时前
dify案例分享-100% 识别率!发票、汇票、信用证全搞定的通用票据识别工作流
前端
拾光拾趣录9 小时前
基础 | HTML语义、CSS3新特性、浏览器存储、this、防抖节流、重绘回流、date排序、calc
前端·面试
小小小小宇9 小时前
前端监测用户卡顿之INP
前端
小小小小宇10 小时前
监测用户在浏览界面过程中的卡顿
前端