Separator =" to "<el-date-picker V-model ="timeRange" type="daterange" range-separator=" to" Placeholder =" yyyY-MM-DD "format=" YYYY-MM-DD" format=" YYYY-MM-DD" :picker-options="pickerOptions" /> data() { return { choiceDate: null, pickerOptions: { onPick: ({ maxDate, minDate }) => { if (minDate && this.choiceDate) { this.choiceDate = null } else if (minDate) { this.choiceDate = minDate.getTime() } }, disabledDate: (time) => {const timeOptionRange = this.choiceDate // Const secondNum = 30 * 24 * 60 * 60 * 1000 if (timeOptionRange) { return (time.getTime() > (this.choiceDate + secondNum)) || (time.getTime() < (this.choiceDate - secondNum)) } return false } } }Copy the code
The month in which you can select only the start date cannot be selected across a month
private choiceDate: any = null private pickerOptions = { onPick: (data: any) => { this.choiceDate = data.minDate if (data.maxDate) { this.choiceDate = null } }, disabledDate: (time: any) => { if (this.choiceDate) { let m: any = this.choiceDate.getMonth() + 1 < 10 ? '0' + (this.choiceDate.getMonth() + 1) : this.choiceDate.getMonth() + 1 const minTime = new Date(this.choiceDate.getFullYear() + '-' + m + '-01 00:00:00') const maxTime = new Date(this.choiceDate.getFullYear(), m, 0) return time.getTime() < minTime || time.getTime() > maxTime } } }
Copy the code