这篇文章编辑与2023.12.26,所以可以选择的时间为包含2023.12.25以及之前的时间
实现思路:1、获取当天时间的年月日,然后默认时分秒为23:59:59;
2、获取到时间转为时间戳减去 一天(1*24*3600*1000)
3、选择的时间大于第二步的时间(禁用逻辑)
代码:页面部分
<el-form-item label="告警时间"><el-date-pickervalue-format="yyyy-MM-dd HH:mm:ss"v-model="time"type="datetimerange":picker-options="pickerOptions"range-separator="~"start-placeholder="开始日期"end-placeholder="结束日期":default-time="pickerDefaultTime"/></el-form-item>
data部分
data() {const that = this;return {pickerDefaultTime: defaultTime,pickerOptions: {disabledDate: this.disabledDateMethod,},time: [],}
}
method部分
disabledDateMethod(time) {let nowData = this.setDate();let firstDay = nowData + " 23:59:59";firstDay = Date.parse(firstDay);let endTime = firstDay - 1 * 24 * 3600 * 1000;return time.getTime() > endTime ;},setDate(day) {let date = new Date();let y = date.getFullYear();let m = date.getMonth() + 1;let d = "";if (day) {d = day;} else {d = date.getDate();}m = m < 10 ? "0" + m : m;d = d < 10 ? "0" + d : d;return y + "-" + m + "-" + d;},},