element ui日期选择器限制时间范围一年内

效果展示:
开始时间:
element ui日期选择器限制时间范围一年内_第1张图片
结束时间:
element ui日期选择器限制时间范围一年内_第2张图片

 <el-form-item label="活动时间" required>
            <el-col :span="11">
              <el-form-item prop="startDate">
                <el-date-picker
                  type="date"
                  placeholder="选择开始日期"
                  v-model="queryParams.startDate"
                  style="width: 100%;"
                  :picker-options="startDateOptions"
                ></el-date-picker>
              </el-form-item>
            </el-col>
            <el-col class="line" :span="2">-</el-col>
            <el-col :span="11">
              <el-form-item prop="endDate">
                <el-date-picker
                  type="date"
                  placeholder="选择结束日期"
                  v-model="queryParams.endDate"
                  style="width: 100%;"
                  :picker-options="EndDateOptions"
                ></el-date-picker>
              </el-form-item>
            </el-col>
          </el-form-item>

data中定义:

  startDateOptions:{
        disabledDate:(time)=>{
            return time.getTime() > Date.now() || time.getTime() == Date.now() || time.getTime()< new Date().setFullYear((new Date().getFullYear()-1))
          }},
  EndDateOptions: {
    disabledDate: (time) => {
      return time.getTime() < new Date(this.statDate).getTime() || time.getTime() > Date.now() || time.getTime() > Date.now(this.statDate)  // 如果当天可选,就不用减8.64e7
    }
  },

你可能感兴趣的:(vue.js,elementui)