限制用户选择时间的范围,如下图所示:?
?
//时间选择器 picker-options属性就是限制选择时间的范围
<el-date-picker
class="input-width"
size="small"
v-model="formPar.periodTime"
type="month"
value-format="yyyy-MM"
format="yyyy-MM"
placeholder="选择日期"
:picker-options="pickerOptions">
</el-date-picker>
data(){
return{
pickerOptions: {
//注意this指向问题
disabledDate: (time) => {
var start = new Date(this.startTime);
var end = new Date(this.endTime);
return (
time.getTime() < start.getTime() || time.getTime() > end.getTime()
);
},
},
startTime:'',
endTime:''
}
}
methods: {
//从接口去获取所要限制时间选择的范围,如果你是固定的也可以直接在上面定义
getContractDetail() {
contractDetail(this.contractId).then((res) => {
this.startTime = res.data.startTime;
this.endTime = res.data.endTime;
});
},
}
|