el-date-picker自定义时间+半年前禁选
效果图
html
<el-date-picker
v-model="analysisTimeRange" value-format="yyyy-MM-dd"
type="daterange" :picker-options="pickerOptions" range-separator="-" start-placeholder="开始日期"
end-placeholder="结束日期" >
</el-date-picker>
JavaScript
pickerOptions: {
shortcuts: [ {
text: '最近一个月',
onClick(picker) {
const start = moment().startOf('date').subtract(1, 'months').toDate()
const end = moment().hours(23).minutes(59).seconds(59).toDate()
picker.$emit('pick', [start, end]); }},
{
text: '最近两个月',
onClick(picker) {
const start = moment().startOf('date').subtract(2, 'months').toDate()
const end = moment().hours(23).minutes(59).seconds(59).toDate()
picker.$emit('pick', [start, end]); } },
{
text: '最近三个月',
onClick(picker) {
const start = moment().startOf('date').subtract(3, 'months').toDate()
const end = moment().hours(23).minutes(59).seconds(59).toDate()
picker.$emit('pick', [start, end]);} },],
disabledDate(v) {
return v.getTime() < new Date().getTime() - 86400000*183;
}
}