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
           } 
         }
     }
	}
}
相关推荐
LucianaiB11 小时前
【元宝搜索开发者征文大赛】AI时代,学得慢就不用学?用元宝搜索打造一个教程保质期,确保每一个教程符合你的现状
前端·人工智能·ai编程
excel12 小时前
JavaScript 对象池:减少高频对象创建与 GC 压力
前端
陈随易13 小时前
纯 Go 写的 JS 引擎,跑分超过了 C 语言的 QuickJS
前端·后端·程序员
子兮曰15 小时前
Chrome 权限元素实战:144 与 151 的渐进增强写法
前端·javascript·chrome
IT_陈寒15 小时前
Redis连接池泄漏那次,我差点把生产环境搞崩了
前端·人工智能·后端
强尼银手15 小时前
我花一天做了个格斗游戏原型,判定全对,然后被「美术」劝退了
前端·javascript
石小石Orz15 小时前
AI 正在蚕食我们的编码能力
前端·后端·算法
陈随易16 小时前
专注飞机 FocusFlight,两个人把番茄钟做成了一趟航班
前端·后端·程序员
总要学点什么17 小时前
第98篇:三维特效-材质线效果——给一条线换十种材质,虚线的图案只填了一半
开发语言·前端·javascript·ecmascript·gis·webgl·材质
10share17 小时前
基于大模型的 i18n 方案:把中文原文当 Key,轻松搞定多语言维护
前端·vue.js