欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

elementUI中日期时间插件(DateTimePicke) 限制结束时间大于开始时间且开始时间小于当前时间

程序员文章站 2022-06-07 13:13:46
...

页面

<span class="searchtime">开始时间:</span>
    <el-date-picker
       size="small"
       v-model="searchingCondition.beginTime"
       type="date"
       :picker-options="startTime"
       placeholder="选择开始日期"
       value-format="yyyy-MM-dd">
   </el-date-picker>
 <span class="searchtime">结束时间:</span>
     <el-date-picker
        size="small"
        v-model="searchingCondition.endTime"
        type="date"
        :picker-options="endTime"
        placeholder="选择结束时间"
        value-format="yyyy-MM-dd">
   </el-date-picker>

方法

     data() {
      return {
        searchingCondition: {  
          beginTime: '',
          endTime: '',
        },
         /* start  */
        startTime: {
          disabledDate: time => {
            if (this.searchingCondition.endTime) {
              return (
                time.getTime() > new Date(this.searchingCondition.endTime).getTime()
              );
            } else {
              return time.getTime() > Date.now();
            }
          }
        },
        endTime: {
          disabledDate: time => {
            if (this.searchingCondition.beginTime) {
              return (
                time.getTime() > Date.now() ||
                time.getTime() < new Date(this.searchingCondition.beginTime).getTime()
              );
            } else {
              return time.getTime() > Date.now();
            }
          }
        },
        /* end*/

      };
    },