el-date-picker当type=“datetime“时限制时分

多的不说,直接上代码

html

   <el-form :model="formData" :rules="rules" ref="form">
      <el-row style="border-top: 1px solid #f1f2f3" class="flex-wrap">
        <el-col :span="12" class="colspan">
          <div class="desc-label">
            <span>开始时间:</span>
          </div>
          <div class="desc-value time-value">
            <el-form-item prop="beginTime" style="width: 100%">
              <el-date-picker
                :picker-options="pickerOptions"
                placeholder="请选择"
                v-model="formData.beginTime"
                value-format="yyyy-MM-dd HH:mm:ss"
                type="datetime"
              />
            </el-form-item>
          </div>
        </el-col>
        <el-col :span="12" class="colspan">
          <div class="desc-label">
            <span>结束时间:</span>
          </div>
          <div class="desc-value time-value">
            <el-form-item prop="endTime" style="width: 100%">
              <el-date-picker
                :picker-options="pickerOptions1"
                placeholder="请选择"
                v-model="formData.endTime"
                value-format="yyyy-MM-dd HH:mm:ss"
                type="datetime"
                :start-placeholder="formData.beginTime"
              />
            </el-form-item>
          </div>
        </el-col>
      </el-row>
    </el-form>

computed

   computed:{
      pickerOptions() {
        return{
        selectableRange:(()=>{
          if(this.formData.endTime){
            let data=new Date(this.formData.endTime);
            let hour=data.getHours();
            let minute=data.getMinutes();
            let second=data.getSeconds();
            return [`00:00:00 - ${hour}:${minute}:${second}`]
          }else {
            return [`00:00:00 - 23:59:59`]
          }
        })(),
        disabledDate: time => {
          if(this.formData.endTime){
            if(new Date(this.formData.endTime).getHours()){
              return time.getTime() > new Date(this.formData.endTime)+86400000
            }else {
              return time.getTime() > new Date(this.formData.endTime)
            }
          }
        },}
      },
      pickerOptions1() {
        return{
          selectableRange:(()=>{
            if(this.formData.beginTime){
              let data=new Date(this.formData.beginTime);
              let hour=data.getHours();
              let minute=data.getMinutes();
              let second=data.getSeconds()+1;
              return [`${hour}:${minute}:${second} - 23:59:59`]
            }else {
              return [`00:00:00 - 23:59:59`]
            }

          })(),
        disabledDate: time => {
          if(this.formData.beginTime){
            if(new Date(this.formData.beginTime).getHours()){
              return time.getTime() < new Date(this.formData.beginTime) -86400000
            }else {
              return time.getTime() < new Date(this.formData.beginTime)
            }
          }
        },}
      },
    },

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值