javascript
<el-date-picker
v-model="startTime"
name="startTime"
value-format="yyyy-MM-dd"
type="date"
@change="activityStartTime"
placeholder="请选择开始日期"
:picker-options="pickerOptions"
/>
<el-date-picker
v-model="endTime"
name="endTime"
value-format="yyyy-MM-dd"
type="date"
@change="activityEndTime"
placeholder="请选择结束日期"
:picker-options="pickerOptions1"
/>
data(){
return{
startTime:new Date(new Date - 1000*60*60*24*31),toLocaleDateString().split('/').map(item=>{if(item<10){return '0'+item}else{return item}}).join('-'),
endTime:new Date().toLocaleDateString().split('/').map(item=>{if(item<10){return '0'+item}else{return item}}).join('-'),
pickerOptions:{},
pickerOptions1:{}
}
}
activityStartTime(val){
this.pickerOptions1 = Object.assign({}, this.pickerOptions,{
disabledDate: time => {
return (
new Date(time).getTime() <= new Date(this.startTime)
)
}
})
}
activityEndTime(val){
if(!value){
this.pickerOptions = Object.assign({}, this.pickerOptions1,{
disabledDate: time => {
return time.getTime() >= new Date("2999-12-30 23:59:59").getTime();
}
})
return
}
this.pickerOptions = Object.assign({}, this.pickerOptions1,{
disabledDate: time => {
return (
time.getTime() >
new Date(this.endTime).getTime() - 24*3600*1000
)
}
})
}
参考:
1、el-date-picker中日期选择器时间限制,限制选择30天时间范围且不大于当前时间 ; 时间范围只能选择1天;时间范围在某一段时间内