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(); 
        },
      },
  }
}
相关推荐
lee57612 分钟前
老是忘记package.json,备忘一下 webpack 环境下 Vue Cli 和 Vite 命令行工具对比
vue.js
喝拿铁写前端1 小时前
前端与 AI 结合的 10 个可能路径图谱
前端·人工智能
codingandsleeping1 小时前
浏览器的缓存机制
前端·后端
灵感__idea3 小时前
JavaScript高级程序设计(第5版):扎实的基本功是唯一捷径
前端·javascript·程序员
摇滚侠3 小时前
Vue3 其它API toRow和markRow
前端·javascript
難釋懷3 小时前
JavaScript基础-history 对象
开发语言·前端·javascript
beibeibeiooo3 小时前
【CSS3】04-标准流 + 浮动 + flex布局
前端·html·css3
拉不动的猪3 小时前
刷刷题47(react常规面试题2)
前端·javascript·面试
浪遏3 小时前
场景题:大文件上传 ?| 过总字节一面😱
前端·javascript·面试
Bigger3 小时前
Tauri(十八)——如何开发 Tauri 插件
前端·rust·app