element-uiで設定した日付の制限時間
8251 ワード
el-date-picker(選択日は当日以降を超えてはいけません.30日間以内に制限します.)
htmlコード
htmlコード
<el-date-picker
v-model="date"
type="datetimerange"
:picker-options="pickerOptions"
range-separator=" "
start-placeholder=" "
end-placeholder=" ">
</el-date-picker>
jsコード pickerMinDate:'',//
pickerMaxDate:'',//
pickerOptions: { //
onPick: ({ maxDate, minDate }) => {
if(minDate){
this.pickerMinDate = minDate.getTime()
}
if (maxDate) {
this.pickerMinDate = ''
this.pickerMaxDate = maxDate.getTime()
}
},
disabledDate: (time) => {
const day30 = (30 - 1) * 24 * 3600 * 1000
if (this.pickerMinDate !== '') {
let maxTime = this.pickerMinDate + day30
if (maxTime > new Date()) {
maxTime = new Date()
}
return time.getTime() > maxTime || time.getTime() > Date.now()
}
if (this.pickerMaxDate !== '' && !this.pickerMinDate) {
let minTime = this.pickerMaxDate - day30
return time.getTime() < minTime || time.getTime() > Date.now()
}
return time.getTime() > Date.now()
}
},