element给的控件其实大多数是不满足需求的,所以有时候需要自己去修改,网上找找就很多方法,但不会写的同志们就犯愁了,也得找到适合自己需求的不是,话不多说,上干货
需求: 可选择当天和往前半年的日期, 其他时间禁止选择
html:
<div class="block">
<span class="demonstration">日期:</span>
<el-date-picker
v-model="rizhi_time"
align="right"
type="date"
placeholder="选择日期"
:picker-options="pickerOptions"
>
</el-date-picker>
</div>
html里面很简单,就添加了一个属性 :picker-options=“pickerOptions”
data数据里面:
disabledDate(time) {
let curDate = new Date().getTime();
let three = 180 * 24 * 3600 * 1000;
let threeMonths = curDate - three;
// var thatDay = time.getTime();
return (
time.getTime() > Date.now() - 8.64e6 || time.getTime() < threeMonths
);
},