直接上代码
<el-date-picker
class="w230"
v-model="formInline.opTime"
type="daterange"
align="right"
unlink-panels
:clearable="false"
value-format="timestamp"
start-placeholder="开始时间"
end-placeholder="结束时间"
:picker-options="pickerOptions"
>
</el-date-picker>
主要配置 => pickerOptions 定义在Data里面就好
const PICKERRANGE = 3600 * 1000 * 24 * 365 //一年的时间戳
data(){
return {
pickerMinDate:null,
pickerOptions: {
onPick: ({ maxDate, minDate }) => {
//pickerMinDate为临时变量 记录开始时间的选择值初始值给空就好
this.pickerMinDate:null, = minDate.getTime();
},
disabledDate: (time) => {
//PICKERRANGE为常量 定义为要选择跨度的时间戳
if (this.pickerMinDate) {
return time.getTime() > this.pickerMinDate + PICKERRANGE;
}
return false;
},
},
}
}