element-ui 日期选择范围,只允许选择上下浮动一个月内的日期区间

  <el-date-picker size="mini"
                  v-model="created_at"
                  value-format="yyyy-MM-dd HH:mm:ss"
                  :picker-options="pickerOptions"
                  clearable
                  type="daterange"
                  start-placeholder="开始日期"
                  end-placeholder="结束日期"
                  :default-time="['00:00:00', '23:59:59']" />
created_at: '',
choiceDate: '',
pickerOptions: {
    onPick: ({ maxDate, minDate }) => {
      this.choiceDate = minDate
      if (maxDate) {
        this.choiceDate = ''
      }
    },

    disabledDate: (time) => {
      if (this.choiceDate !== '') {
        return time.getTime() < moment(this.choiceDate).subtract(1, 'month') ||
          (time.getTime() > moment(this.choiceDate).add(1, 'month').endOf('day') && time.getTime() < moment().endOf('day')) ||
          time.getTime() > moment().endOf('day')
      }
      return time.getTime() > moment().endOf('day')
    }
}
评论数量: 0

1
点赞
1936
浏览
0
评论

贡献 60