ElementUI时间控件el-date-picker选择时间范围固定(不

2024年06月23日 建站教程

template部分就不介绍了,只要el-date-picker控件里带:picker-options="pickerOptions"有可以

script部分:

export default {
  data() {
    return {
      selectHospital: [],
      selectHospitalValue: "",
      pickerOptions: {
        onPick: time => {
          //当第一时间选中才设置禁用
          if (time.minDate && !time.maxDate) {
            this.timeOptionRange = time.minDate;
          }
          if (time.maxDate) {
            this.timeOptionRange = null;
          }
        },
        disabledDate: time => {
          let timeOptionRange = this.timeOptionRange;
          let secondNum = 60 * 60 * 24 * 6 * 1000;
          if (timeOptionRange) {
            if (timeOptionRange.getTime() + secondNum > Date.now() - 8.64e6) {
              return (
                time.getTime() > Date.now() - 8.64e6 ||
                time.getTime() < timeOptionRange.getTime() - secondNum
              );
            }
            return (
              time.getTime() > timeOptionRange.getTime() + secondNum ||
              time.getTime() < timeOptionRange.getTime() - secondNum
            );
          }
        }
      }
    }
  }
}

本文链接:http://so.lmcjl.com/news/7122/

展开阅读全文
相关内容