ant-design date-picker 可以选择当天,时间不能选择过去的小时
不得不说moment真厉害啊,是我之前低估他了
我这里是可以选择到具体的分钟的
<a-date-picker v-model="chooseDate" placeholder="年-月-日" :inputReadOnly="true" :show-time="showTime" format="YYYY-MM-DD HH:mm" value-format="YYYYMMDD HH:mm" autocomplete="off" :disabledDate="disabledDate" style="width: 100%" />
import moment from "moment"; //引入一下moment
//在数据里面定义一下
data() {
return {
moment,
chooseDate:'',// 日期
lastDate:'2030-12-12',// 截至日期 (没有截止日期可以不要哈)
showTime: {
format: "HH:mm",
defaultValue: moment(moment().add(1, 'hour').format('HH'), "HH:mm"),//默认时间往后加一个小时
},
};
},
在methods里面新增disabledDate 方法, // 不可选日期 不过不加30s的话,可能当天选不了,因为时间截止到分钟,影响不大太
disabledDate(current) {
return current && current.isBefore(moment().subtract(30, 'second')) || current > moment(this.lastDate).endOf("day");
},