不能选择今天之后日期以及选择日期最多跨度三个月(el-date-picker)

发布时间 2023-11-09 16:25:14作者: 林陌桑

 

pickerOptions: {
        onPick: ({ maxDate, minDate }) => {
          this.pickDate = minDate.getTime()
          if (maxDate) {
            this.pickDate = ''
          }
        },
        disabledDate: time => {
          const choiceDateTime = new Date(this.pickDate).getTime()
          const minTime = new Date(choiceDateTime).setMonth(new Date(choiceDateTime).getMonth() - 3)
          const maxTime = new Date(choiceDateTime).setMonth(new Date(choiceDateTime).getMonth() + 3)
          const min = minTime
          const max = maxTime
          if (this.pickDate) {
            return time.getTime() < min || time.getTime() > max || time.getTime() > Date.now() - 8.64e7
          } else {
            return time.getTime() > Date.now() - 8.64e7
          }
        }
      }