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
           } 
         }
     }
	}
}
相关推荐
一心赚狗粮的宇叔11 分钟前
web全栈开发学习-01html基础
前端·javascript·学习·html·web
IT瘾君11 分钟前
JavaWeb:前端工程化-ElementPlus
前端·elementui·node.js·vue
爱编程的鱼13 分钟前
如何在 HTML 中添加按钮
前端·javascript·html
鱼与宇13 分钟前
WebSphere(WAS)
前端·chrome
站在风口的猪110820 分钟前
《前端面试题:前端布局全面解析(圣杯布局、双飞翼布局等)》
前端·css·html·css3·html5
IT瘾君20 分钟前
JavaWeb:前后端分离开发-部门管理
开发语言·前端·javascript
mldong32 分钟前
我的全栈工程师之路:全栈学习路线分享
前端·后端
江城开朗的豌豆1 小时前
JavaScript篇:"闭包:天使还是魔鬼?6年老司机带你玩转JS闭包"
前端·javascript·面试
早知道不学Java了1 小时前
chromedriver 下载失败
前端·vue.js·react.js·npm·node.js
江城开朗的豌豆1 小时前
JavaScript篇:解密JS执行上下文:代码到底是怎么被执行的?
前端·javascript·面试