<el-form-item label="" class="inline-block" prop="sellTime">
<el-date-picker
:clearable="false"
v-model="shopConfig.sellTime"
type="datetime"
placeholder="选择日期时间"
:picker-options="pickerOptions"
value-format="yyyy-MM-dd HH:mm:ss"
class="taskTimes ml-10 wSize-n"
></el-date-picker>
</el-form-item>
computed: {
pickerOptions() {
//如果选择的⽇期为最⼩⽇期,则设置为最⼩⽇期的时分秒
let str = ''
if (moment().isSame(moment(this.shopConfig.sellTime), 'day')) {
str = moment().add(1, 'H').format('HH:00:00')
} else {
str = '00:00:00'
}
return {
disabledDate: time => {
return time.getTime() < Date.now() - 3600 * 1000 * 24 // 选当前时间之后的时间
},
selectableRange: str + ' - 23:59:59'
}
},
//30天区间
pickerOptions() {
//如果选择的⽇期为最⼩⽇期,则设置为最⼩⽇期的时分秒
let startStr = '00:00:00'
let finishStr = '23:59:59'
if (moment().isSame(moment(this.shopConfig.sellTime), 'day')) {
startStr = moment().add(1, 'H').format('HH:00:00')
finishStr = '23:59:59'
} else if (moment().add(29, 'day').isSame(moment(this.shopConfig.sellTime), 'day')) {
startStr = '00:00:00'
finishStr = moment().add(29, 'day').format('HH:mm:ss')
}
return {
disabledDate: time => {
const t = time.getTime()
const n = new Date(new Date().setHours(0, 0, 0, 0)).getTime()
return t < n || time > n + 2505600000 // 30天
},
selectableRange: startStr + '-' + finishStr
}
}
},
记录:vue+element:DateTimePicker 不能选择当前时间前的时间(包括时分秒)
于 2022-07-06 12:08:44 首次发布