element-ui日期选择器时间范围设定

需求:开始日期和结束日期差不能大于一个月,选取的日期不能大于当前日期。

 <el-date-picker
          v-model="pickTime"
          type="daterange"
          range-separator="至"
          start-placeholder="开始日期"
          end-placeholder="结束日期"
          @change="datePickEnd"
          value-format="yyyy-MM-dd"
          :class="{'active':searchType == 4}"
          :picker-options="pickerOptions"
        ></el-date-picker>
      pickerOptions: {
        onPick: ({ maxDate, minDate }) => {
          this.choiceDate = minDate.getTime();
          if (maxDate) {
            this.choiceDate = "";
          }
        },
        disabledDate: time => {
          if (this.choiceDate) {
            const one = 30 * 24 * 3600 * 1000;
            const minTime = this.choiceDate - one;
            const maxTime =
              this.choiceDate + one > Date.now() - 8.64e6
                ? Date.now() - 8.64e6
                : this.choiceDate + one;
            return time.getTime() < minTime || time.getTime() > maxTime;
          } else {
            return time.getTime() > Date.now() - 8.64e6;
          }
        }
      },
      choiceDate: ""

 

posted @ 2018-12-22 11:31  活着ing  阅读(718)  评论(0编辑  收藏  举报