el-date-picker (选择日期不能大于当天之后,并且限制在30天之内)
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()
}
},