<el-date-picker v-model="form.startDate" style="width:160px;" type="date" value-format="yyyy-MM-dd" placeholder="请选择开始时间" :picker-options="startTime"></el-date-picker>
<el-date-picker v-model="form.endDate" style="width:160px;" type="date" value-format="yyyy-MM-dd" placeholder="请选择结束时间" :picker-options="endTime"></el-date-picker>
export default {
data(){
return{
startTime: {
disabledDate: (time) => {
return time.getTime() > Date.now() //不能选择当天之后的日期
}
},
endTime: {
disabledDate: (time) => {
let startDate = new Date(this.form.startDate).getTime() //获取开始时间的时间戳
let day = new Date(startDate)
day = day.setDate(day.getDate() - 1) //获取开始时间的前一天
if (startDate) {
return (time.getTime() < day || time.getTime() > Date.now()) //不能选择开始时间之前的日期及当天之后的日期
} else {
return time.getTime() > Date.now() //不能选择当天之后的日期
}
}
}
}
}