elementui的el-date-picker选择日期范围第二个不能早于第一个

选择日期范围第二个不能早于第一个

复制代码
          <el-form-item label="预计施工时间:" required>
            <el-form
              :model="form"
              :rules="constructionDateRules"
              ref="constructionRef"
              inline
              :hide-required-asterisk="false"
            >
              <el-form-item prop="constructionStartDate">
                <el-date-picker
                  value-format="yyyy-MM-dd"
                  v-model="form.constructionStartDate"
                  type="date"
                  placeholder="开工日期"
                 
                  style="width: 196px; margin-right: 8px"
                >
                </el-date-picker>
              </el-form-item>
              <el-form-item prop="constructionEndDate">
                <el-date-picker
                  value-format="yyyy-MM-dd"
                  v-model="form.constructionEndDate"
                  type="date"
                  placeholder="竣工日期"
                  style="width: 196px"
                  :picker-options="pickerOptions"
                >
                </el-date-picker>
              </el-form-item>
            </el-form>
          </el-form-item>

data(){
	return {
		    //判断时间选择上个选择时间之后的时间
    pickerOptions: {
      disabledDate: (time) => {
        if (this.form.constructionStartDate != "") {
          return (
            time.getTime() <
              new Date(this.form.constructionStartDate).getTime()
          );
        }else{
            this.$message.warning('请先选择开工日期')
          }
      },
    },
	}
}

选择第一个日期不能早于今天

选择日期范围第二个不能早于第一个

复制代码
          <el-form-item label="预计施工时间:" required>
            <el-form
              :model="form"
              :rules="constructionDateRules"
              ref="constructionRef"
              inline
              :hide-required-asterisk="false"
            >
              <el-form-item prop="constructionStartDate">
                <el-date-picker
                  value-format="yyyy-MM-dd"
                  v-model="form.constructionStartDate"
                  type="date"
                  placeholder="开工日期"
                  :picker-options="pickerOptions1"
                  style="width: 196px; margin-right: 8px"
                >
                </el-date-picker>
              </el-form-item>
              <el-form-item prop="constructionEndDate">
                <el-date-picker
                  value-format="yyyy-MM-dd"
                  v-model="form.constructionEndDate"
                  type="date"
                  placeholder="竣工日期"
                  style="width: 196px"
                  :picker-options="pickerOptions2"
                >
                </el-date-picker>
              </el-form-item>
            </el-form>
          </el-form-item>

data(){
	return {
pickerOptions1: {
             disabledDate(time) {
                 var timeNow = Date.now()
                 var before = timeNow - 24 * 60 * 60 * 1000
                 return time.getTime() < before;
             },
         },

//判断时间选择上个选择时间之后的时间
    pickerOptions2: {
        disabledDate: (time) => {
         var timeNow = Date.now()
         var before = timeNow - 24 * 60 * 60 * 1000
          if (this.form.jzdate != "") {
             return time.getTime() < new Date(this.form.jzdate).getTime() || time.getTime() < Date.now() - 8.64e7;
           }else{//还没有选择结束时间的时候,让他只能选择今天之后的时间包括今天
             return time.getTime() < before
           } 
         }
     }
	}
}
相关推荐
bearpping14 小时前
Nginx 配置:alias 和 root 的区别
前端·javascript·nginx
@大迁世界14 小时前
07.React 中的 createRoot 方法是什么?它具体如何运作?
前端·javascript·react.js·前端框架·ecmascript
January120714 小时前
VBen Admin Select 选择框选中后仍然显示校验错误提示的解决方案
前端·vben
. . . . .14 小时前
前端测试框架:Vitest
前端
xiaotao13115 小时前
什么是 Tailwind CSS
前端·css·css3
战南诚16 小时前
VUE中,keep-alive组件与钩子函数的生命周期
前端·vue.js
发现一只大呆瓜16 小时前
React-彻底搞懂 Redux:从单向数据流到 useReducer 的终极抉择
前端·react.js·面试
霍理迪16 小时前
Vue的响应式和生命周期
前端·javascript·vue.js
李剑一16 小时前
别再瞎写了!Cesium 模型 360° 环绕,4 套源码全公开,项目直接用
前端