a-date-picker设置禁用以前的时间(含时分秒)

 

<a-date-picker 
  v-model="selectTime" 
  show-time 
  format="YYYY/MM/DD HH:mm:ss" 
  valueFormat="YYYY-MM-DD HH:mm:ss" 
  :disabled-date="disabledDate"
  :disabled-time="disabledTime"
  placeholder="请选择时间"  />

 

import moment from 'moment';
// 设置禁用日期(年月日) disabledDate(current) { // 禁用今天之前的日期 return moment(current).add(1, 'day') < new Date() },

// 设置禁用的时分秒 disabledTime(current) { return { disabledHours: () => this.getDisabledHours(current || moment(new Date())), disabledMinutes: () => this.getDisabledMinutes(current || moment(new Date())), disabledSeconds: () => this.getDisabledSeconds(current || moment(new Date())), }; }, getDisabledHours(date) { const hours = []; for (let i = 0; i < 24; i++) { if (moment().isAfter(date.clone().hour(i))) { hours.push(i); } } return hours; }, getDisabledMinutes(date) { const minutes = []; for (let i = 0; i < 60; i++) { if (moment().isAfter(date.clone().minute(i))) { minutes.push(i); } } return minutes; }, getDisabledSeconds(date) { const seconds = []; for (let i = 0; i < 60; i++) { if (moment().isAfter(date.clone().second(i))) { seconds.push(i); } } return seconds; }

 

posted @ 2023-12-25 16:29  青云码上  阅读(302)  评论(0编辑  收藏  举报