一、想要的效果
二、实现步骤
1、引入日期、时间组件代码
<a-date-picker @change="getSwitchData" :disabled-date="disabledDate" format="YYYY-MM-DD" :showToday="false" v-model="schedulerForm.schedule_createDate" />
<a-time-picker :disabledHours="getDisabledHours" :disabledMinutes="getDisabledMinutes" format="HH:mm" v-model="schedulerForm.schedule_createTime" />
2、引入时间插件
import moment from ‘moment’
3、js函数
export default {
data() {
return {
schedulerOldData: ''
},
methods: {
// 1、首先获取选择的日期
getSwitchData(date, dateString) {
this.schedulerOldData = dateString
},
// 2、禁用日期
disabledDate(current) {
return current && current < moment().subtract(1, 'day')
},
// 3、禁用小时
getDisabledHours() {
var hours = []
let isAfter = moment(this.schedulerOldData).isAfter(moment())
if (!isAfter) {
for (var i = 0; i < moment().hour(); i++) {
hours.push(i)
}
} else {
hours = []
}
return hours
},
// 4、禁用分钟
getDisabledMinutes(selectedHour) {
var Minutes = []
let isAfter = moment(this.schedulerOldData).isAfter(moment())
let isMinutesAfter = moment().hours() < selectedHour
if (!isAfter && !isMinutesAfter) {
for (var i = 0; i < moment().minutes(); i++) {
Minutes.push(i)
}
} else {
Minutes = []
}
return Minutes
},
}
}
}