element-ui日期选择器限制选择范围

  • 只能选当日或之前的日期
//页面中的
<el-date-picker type="date" value-format="timestamp" v-model="form.birthDate" placeholder="选择日期" class="display-block" :picker-options="pickerBeginDateBefore"></el-date-picker>
//放在data中的
pickerBeginDateBefore: {
        disabledDate: time => {
          let _now = Date.now();
            return time.getTime() > _now;
        }
      },
  • 选时间段之间的范围
            <el-form-item label="入住日期" class="inline">
              <el-date-picker value-format="timestamp" v-model="params.startDate" type="date" :picker-options="pickerBeginDateBefore" placeholder="选择日期">
              </el-date-picker>
              <span class="item-font"></span>
              <el-date-picker value-format="timestamp" v-model="params.endDate" type="date" :picker-options="pickerBeginDateAfter" placeholder="选择日期">
              </el-date-picker>
            </el-form-item>
//data中的
      pickerBeginDateBefore: {
        disabledDate: time => {
          let beginDateVal = this.params.endDate;
          if (beginDateVal) {
            return time.getTime() > beginDateVal;
          }
        }
      },
      pickerBeginDateAfter: {
        disabledDate: time => {
          let beginDateVal = this.params.startDate;
          if (beginDateVal) {
            return time.getTime() < beginDateVal;
          }
        }
      },

你可能感兴趣的:(element-ui)