When iview DatePicker initially has a default value, the unselectable date set by options does not work.

set an unselectable date, the code is as follows:

<DatePicker type="date" format="yyyy-MM-dd" placeholder="" :value="time1" :options="tOption1" @on-change="time1Change" style="width: 90%;"></DatePicker>

<DatePicker type="date" format="yyyy-MM-dd" placeholder="" :value="time" :options="tOption2" @on-change="time2Change" style="width: 90%;"></DatePicker>

at first, two unselectable dates are set in data () , neither today nor later can be selected, as follows:

      tOption1: {
        disabledDate (date) {
          return date && date.valueOf() > Date.now() - 86400000
        }
      },
      tOption2: {
        disabledDate (date) {
          return date && date.valueOf() > Date.now() - 86400000
        }
      }

then in their change method, set the limit that time1 is earlier than time2 when the time is selected:

    time1Change: function (e) {
      //time1 time2 time1
      this.tOption2= {
        disabledDate: date => {
          let time = e ? new Date(e).valueOf() : ""
          return (date && (date.valueOf() < time)) || (date && date.valueOf() > Date.now() - 86400000)
        }
      }
    },
    time2Change: function (e) {
      //time2 time1 time2
      this.tOption1= {
        disabledDate: date => {
          let time = e ? new Date(e).valueOf() : ""
          return e ? (date && (date.valueOf() > time - 86400000)) : (date && date.valueOf() > Date.now() - 86400000)
          //time2
        }
      }
    }

effect is normal, as shown in figure


1;
2time1change time2time1time2 change

,:

2018-10-03change:

so, when DatePicker initially has a default value, the unselectable date set by options in data () doesn"t work. How is that?

what is even more inexplicable is that in our project, another page also needs to set unselectable dates. By the same logic, DatePicker has default values and no default values. At first, the unselectable dates set by options in data () are all normal, damn it.

Nov.20,2021

there is nothing wrong with the logic of setting an unselectable date in the above question. the logic written in other projects is normal, and it can display an unselectable date normally with a default value at first, anyway. Hehe

later, in this damn place, the demand changed to just the year:

<DatePicker type="year" format="yyyy" placeholder="" :value="time1" :options="tOption1" @on-change="time1Change" style="width: 90%;"></DatePicker>

<DatePicker type="year" format="yyyy" placeholder="" :value="time" :options="tOption2" @on-change="time2Change" style="width: 90%;"></DatePicker>

set in data ():

tOption1: {
        disabledDate (date) {
          return date && date.getFullYear() > new Date().getFullYear()
        }
      },
      tOption2: {
        disabledDate (date) {
          return date && date.getFullYear() > new Date().getFullYear()
        }
      }

change method:

time1Change: function (e) {
      //time1 time2 time1
      this.tOption2= {
        disabledDate: date => {
          let time = e ? new Date(e).getFullYear() : ''
          return (date && (date.getFullYear() < time)) || (date && date.getFullYear() > new Date().getFullYear())
        }
      }
    },
    time2Change: function (e) {
      //time2 time1 time2
      this.tOption1= {
        disabledDate: date => {
          let time = e ? new Date(e).getFullYear() : ''
          return e ? (date && (date.getFullYear() > time)) : (date && date.getFullYear() > new Date().getFullYear())//time2
        }
      }
    }

then the damn bug is gone. It's gone.

MySQL Query : SELECT * FROM `codeshelper`.`v9_news` WHERE status=99 AND catid='6' ORDER BY rand() LIMIT 5
MySQL Error : Disk full (/tmp/#sql-temptable-64f5-1bee5a8-31bfb.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
MySQL Errno : 1021
Message : Disk full (/tmp/#sql-temptable-64f5-1bee5a8-31bfb.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
Need Help?