HTML
<el-date-picker
v-model="sbForm.cj_time"
:clearable="false"
:editable="false"
:picker-options="pickerOptions"
type="date"
value-format="yyyy-MM-dd"
@change="refeshZcAll"
>
</el-date-picker>
方法一:无判断data执行
js
data(){
return{
pickerOptions: {
const date = new Date();
const year = date.getFullYear();
const month = date.getMonth() + 1;
const strings = this.tradeSequenceData.execute_day.split(",");
const startDay =
Number(strings[0]) < 10
? "0" + Number(strings[0])
: Number(strings[0]);
const endDay = Number(strings[1]) < 10 ? "0" + strings[1] : strings[1];
const startTime = year + "-" + month + "-" + startDay;
const endTime = year + "-" + month + "-" + endDay;
console.log(startTime, endTime);
return (
time.getTime() < new Date(startTime).getTime() ||
time.getTime() > new Date(endTime).getTime()
);
},
}
}
方法一:有逻辑判断methods执行
methods(
disabledGetTime(time) {
if (this.tradeSequenceData.execute_type !== "2") {
return time.getTime() > Date.now(); //禁用当天之后的时间不可选择(disabledDate中,time.getTime() 的范围是禁用的时间范围)
} else if (this.tradeSequenceData.execute_type === "2") {
const date = new Date();
const year = date.getFullYear();
const month = date.getMonth() + 1;
const strings = this.tradeSequenceData.execute_day.split(",");
const startDay =
Number(strings[0]) < 10
? "0" + Number(strings[0])
: Number(strings[0]);
const endDay = Number(strings[1]) < 10 ? "0" + strings[1] : strings[1];
const startTime = year + "-" + month + "-" + startDay;
const endTime = year + "-" + month + "-" + endDay;
console.log(startTime, endTime);
return (
time.getTime() < new Date(startTime).getTime() ||
time.getTime() > new Date(endTime).getTime()
);
}
},
)
startTime:限制范围的开始时间,endTime:限制范围的结束时间;disabledDate中,time.getTime() 的范围是禁用的时间范围