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(); 
        },
      },
  }
}
相关推荐
世界哪有真情2 分钟前
用虚拟IP扩容端口池:解决高并发WebSocket端口耗尽问题
前端·后端·websocket
前端世界3 分钟前
打造一个可维护、可复用的前端权限控制方案(含完整Demo)
前端
LeQi8 分钟前
当!important成为代码毒瘤:你的项目是不是也中了招?
前端·css·程序员
玲小珑10 分钟前
Next.js 教程系列(九)增量静态再生 (ISR):动态更新的静态内容
前端·next.js
Mintopia18 分钟前
B 样条曲线:计算机图形学里的 “曲线魔术师”
前端·javascript·计算机图形学
前端小巷子21 分钟前
跨域问题解决方案:CORS(跨域资源共享)
前端·网络协议·面试
大大。22 分钟前
van-tabbar-item选中active数据变了,图标没变
java·服务器·前端
Mintopia24 分钟前
Three.js 3D 世界中的噪声运动:当数学与像素共舞
前端·javascript·three.js
paopaokaka_luck24 分钟前
基于SpringBoot+Vue的酒类仓储管理系统
数据库·vue.js·spring boot·后端·小程序
nc_kai25 分钟前
Flutter 之 每日翻译 PreferredSizeWidget
java·前端·flutter