element 选择时间在两个时刻之间
需求:学生选择假期,再选取时间,时间必须在假期中
核心代码
<el-date-picker
v-model="value1"
type="date"
placeholder="选择日期"
:picker-options="pickerOptionsStartTime">
</el-date-picker>
data(){
return {
vacation_start_time:'2021-12-20 10:54:16',
pickerOptionsStartTime:{
disabledDate:(time)=>{
return time.getTime() < new Date(Date.parse(this.vacation_start_time)) || new Date(Date.parse(this.vacation_end_time)) < time.getTime() ;
}
},
}
}
<el-form-item label="申请假期">
<el-autocomplete
v-model="stayAtSchoolForm.stay_at_school_id"
:fetch-suggestions="stay_at_school_idQuerySearchAsync"
placeholder="请输入内容"
@select="stay_at_school_idHandleSelect"
></el-autocomplete>
</el-form-item>
<el-form-item label="开始时间 ">
<el-date-picker
v-model="stayAtSchoolForm.start_date"
type="datetime"
:disabled="disableTime"
:picker-options="pickerOptionsStartTime"
placeholder="选择日期时间">
</el-date-picker>
</el-form-item>
<el-form-item label="结束时间 ">
<el-date-picker
v-model="stayAtSchoolForm.end_date"
type="datetime"
:disabled="disableTime"
:picker-options="pickerOptionsEndTime"
placeholder="选择日期时间">
</el-date-picker>
</el-form-item>
data() {
return {
省略代码***
//用()=>{} 就能拿到this,就能拿到数据。用 函数名(){}就拿不到this
pickerOptionsStartTime:{
disabledDate:(time)=>{
return time.getTime() < new Date(Date.parse(this.vacation_start_time)) || new Date(Date.parse(this.vacation_end_time)) < time.getTime() ;
}
},
//用()=>{} 就能拿到this,就能拿到数据。用 函数名(){}就拿不到this
pickerOptionsEndTime:{
disabledDate:(time)=>{
return new Date(Date.parse(this.vacation_end_time)) < time.getTime() || time.getTime() < new Date(Date.parse(this.vacation_start_time)) || time.getTime() < new Date(Date.parse(this.stayAtSchoolForm.start_date)) ;
}
},
}
},
效果
总结
- 用()=>{} 就能拿到this,就能拿到数据。用 函数名(){}就拿不到this
- || 这里表示都成立
疑问
|| 在JavaScript中表示返回第一个有效值,这里为什么这样用?