第一步:
<el-date-picker
v-model="editObj.orderTime"
type="datetime"
placeholder="选择日期时间"
format="yyyy-MM-dd HH:mm"
value-format="yyyy-MM-dd HH:mm"
@change="handle"
:picker-options="pickerOptions"
>
</el-date-picker>
第二步:
在data里面
pickerOptions: {
selectableRange: `${this.getTimer()}-23:59:59`,
disabledDate(time) {
return time.getTime() < Date.now() - 3600 * 1000 * 24;
},
},
第三步:
getTimer() {
var date = new Date();
var h = date.getHours();
h = h < 10 ? "0" + h : h;
var min = date.getMinutes();
min = min < 10 ? "0" + min : min;
var s = date.getSeconds();
s = s < 10 ? "0" + s : s;
return h + ":" + min + ":" + s;
},
handle() {
const myDate = new Date(Date.now());
if (this.editObj.orderTime < myDate) {
this.editObj.orderTime = myDate;
}
}
结束。