禁用今天之前日期的示例代码,参考一下:
<template>
<el-date-picker v-model="date" type="date" :picker-options="pickerOptions" />
</template>
<script>
export default {
data() {
return {
date: '',
pickerOptions: {
disabledDate(time) {
const today = new Date();
today.setHours(0, 0, 0, 0);
return time.getTime() < today.getTime();
}
}
}
}
}
</script>在这里,我们将 disabledDate 作为 pickerOptions 对象的属性传递给 <el-date-picker>,并在 disabledDate 函数中使用 getTime() 比较日期的时间戳。注意,我们在比较时间戳之前,还需要将今天的时间戳设置为 0 点以便进行比较,否则可能会出现时间偏移的问题。










