只能选到日期,不选时间,end的时间戳比start的时间戳大,不能跨月且年月相同
在 el-date-pickerel-date-picker 设置picker-options参数,:picker-options="pickerOptions"
在data定义pickerOptions
<el-date-picker format="yyyy-MM-dd" value-format="timestamp" v-model="起始时间" type="date" :picker-options="pickerOptions"></el-date-picker>
<el-date-picker format="yyyy-MM-dd" value-format="timestamp" v-model="结束时间" type="date" :picker-options="pickerOptionsEnd"></el-date-picker>
data() {
return {
pickerOptionsEnd: {
disabledDate: time => {
const now = new Date(this.结束时间);
const year = now.getFullYear();
const month = now.getMonth();
const date = now.getDate();
const firstDayOfMonth = new Date(year, month, date);
const lastDayOfMonth = new Date(year, month + 1, 0);
return time.getTime() < firstDayOfMonth.getTime() || time.getTime() > lastDayOfMonth.getTime();
}
},
pickerOptions: {
disabledDate: time => {
const now = new Date(this.开始时间);
const year = now.getFullYear();
const month = now.getMonth();
const date = now.getDate();
const firstDayOfMonth = new Date(year, month, 1);
const lastDayOfMonth = new Date(year, month, date);
return time.getTime() < firstDayOfMonth.getTime() || time.getTime() > lastDayOfMonth.getTime();
}
},
}
}
效果图如下: