DatePicker 日期选择器选择月份 只能选择当前月份之前的12个月份

<el-date-picker
            v-model="value2"
            type="month"
            :picker-options="pickerOptions"
            placeholder="选择月"
          >
          </el-date-picker>
 data() {
    return {
      pickerOptions: {
        disabledDate(val) {
          const month = new Date(val).getMonth();
          const currentMonth = new Date().getMonth();
          const year = new Date(val).getFullYear();
          const currentYear = new Date().getFullYear();
          const currenTime = new Date().getTime();
          const time = new Date(val).getTime();

          if (
            year < currentYear - 1 ||
            time > currenTime ||
            (year < currentYear && month < currentMonth)
          ) {
            return true;
          }
        }
      },
  }
}

  

posted @ 2022-08-19 16:55  你丫才美工  阅读(1149)  评论(0编辑  收藏  举报