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(); 
        },
      },
  }
}
相关推荐
mCell2 小时前
GSAP ScrollTrigger 详解
前端·javascript·动效
gnip2 小时前
Node.js 子进程:child_process
前端·javascript
excel5 小时前
为什么在 Three.js 中平面能产生“起伏效果”?
前端
excel6 小时前
Node.js 断言与测试框架示例对比
前端
天蓝色的鱼鱼8 小时前
前端开发者的组件设计之痛:为什么我的组件总是难以维护?
前端·react.js
codingandsleeping8 小时前
使用orval自动拉取swagger文档并生成ts接口
前端·javascript
石金龙9 小时前
[译] Composition in CSS
前端·css
白水清风9 小时前
微前端学习记录(qiankun、wujie、micro-app)
前端·javascript·前端工程化
Ticnix9 小时前
函数封装实现Echarts多表渲染/叠加渲染
前端·echarts
用户22152044278009 小时前
new、原型和原型链浅析
前端·javascript