<el-date-picker v-model="value2" type="datetime" placeholder="选择日期时间" align="right" :picker-options="pickerOptions"> </el-date-picker>
pickerOptions: {
disabledDate: time => {
return time.getTime() < new Date().getTime() -86400000
},
selectableRanage: this.timeRanage(new Date())+' - 23:59:59',
}
timeRanage(time) {
let format = 'hh:mm:ss';
if(time != 'Invalid Date'){
var o = {
'M+': time.getMonth()+1,
'd+': time.getDate(),
'h+': time.getHours(),
'm+': time.getMinutes(),
's+': time.getSeconds(),
'q+': Math.floor((time.getMonth()+3)/3),
S: time.getMillSeconds(),
};
if(/(y+)/.test(format)){
format = format.replace(
RegExp.$1,(tiem.getFullYear()).substr(4-RegExp.$1.length)
)
}
for(let k in o){
if(new RegExp('('+k+')').test(format)){
format = format.replace(
RegExp.$1,RegExp.$1.length == 1 ? o[k] : ('00'+o[k]).substr((''+o[k]).length)
)
}
}
return format;
}
return '';
}
注意:
1.timeRanage方法为借鉴其他博主的,但由于没有找到作者,若侵权,请联系,即刻删除!
2.如果时间不能获取到实时时间,可以在时间组件出现的页面加载初始(比如:mounted/el-dialog:visible=true),设置定时任务setInterval(()=>{
this.pickerOptions.selectableRanage = this.timeRanage(new Date())+' - 23:59:59',
},1000)
3.当页面被关闭时,clearInterval 关闭定时任务;