el-date-picker 时间控件校验选择时间必须早于当前时间(带时分秒)

el-date-picker 时间控件校验选择时间必须遭早于当前时间(带时分秒),然后监控时间控件,当时间改变的时候,如果不是当天,那时间可以选择全天也就是00-24时,如果是当天,就是当前时间之前

html部分

复制代码
 <el-form-item label="注销时间" prop="logoutTime">
                <el-date-picker
                  v-model="formData.logoutTime"
                  :placeholder="'请选择注销时间'"
                  type="datetime"
                  :picker-options="pickerOptions"

                  style="width: 200px">
                </el-date-picker>
              </el-form-item>

//js部分

复制代码
data(){

pickerOptions: {
  disabledDate(time) {
    const date = new Date();
    return time.getTime() > new Date().getTime();
    // return time.getTime() > new Date().getTime() - 86400000;//这个不包含当天
  },
  selectableRange: (() => {
    let data = new Date();
    let hour = data.getHours();
    let minute = data.getMinutes();
    let second = data.getSeconds();
    return [`00:00:01 - ${hour}:${minute}:${second}`]
  })(),
},
}

//监听时间控件的改变值
    watch: {
  
      'formData.logoutTime':{
        handler(newVal, oldVal) {
          //这里判断是不是今天
         let newValDate= new Date(newVal)//转换成中国标准时间
          if (
            newValDate &&newValDate.getFullYear() == new Date().getFullYear() &&
            newValDate.getMonth() == new Date().getMonth() &&
            newValDate.getDate() == new Date().getDate()
          ) {
            //如果为今天,则限制当前时间后的时间不能选择。
            let data = new Date();
            let hour = data.getHours();
            let minute = data.getMinutes();
            let second = data.getSeconds();
            this.pickerOptions.selectableRange = [`00:00:01 - ${hour}:${minute}:${second}`]
          }else{
            //如果不是今天,则不用限制
            this.pickerOptions.selectableRange = "00:00:00 - 23:59:00";
          }
        }
      }
    },
相关推荐
KaMeidebaby2 小时前
卡梅德生物技术快报|PD1 单克隆抗体定制配套 N 糖全谱质控开发
前端·人工智能·算法·数据挖掘·数据分析
nuIl3 小时前
实现一个 Coding Agent(3):工具调用
前端·agent·cursor
nuIl3 小时前
实现一个 Coding Agent(4):ReAct 循环
前端·agent·cursor
nuIl3 小时前
实现一个 Coding Agent(1):一次 LLM 调用
前端·agent·cursor
nuIl3 小时前
实现一个 Coding Agent(2):让 LLM 流式响应
前端·agent·cursor
copyer_xyf3 小时前
Python 异常处理
前端·后端·python
sugar__salt3 小时前
从栈队列数据结构到JS原型面向对象全解
前端·javascript·数据结构
MageGojo3 小时前
随机文案模块怎么做?从接口封装到前端展示的完整实现思路
javascript·前端开发·api接口·后端开发·随机文案
独特的螺狮粉3 小时前
篮球集训班器具管理系统 - 鸿蒙PC Electron框架完整技术实现指南
前端·javascript·华为·electron·前端框架·开源·鸿蒙
小妖6663 小时前
js 生成随机数技巧 Math.random().toString(36)
javascript·随机数