element ui 的 el-date-picker 日期选择组件设置可选日期范围

有时候,在使用日历控件的时候,我们需要进行定制,控制用户只能在指定日期范围内进行日期选择,在这里,我使用了 element ui 的 el-date-picker 日期选择控件,控制只能选择当前月及往前的2个月,效果如图:

HTML代码:

html 复制代码
<template>
    <el-date-picker :picker-options="pickerOptions" type="month" placeholder="选择月" v-model="monthsVal"></el-date-picker>
</template>

JS代码:

javascript 复制代码
<script>
export default {
    data() {
        return {
            monthsVal:'',
            pickerOptions: {
                disabledDate(time) {
                    const currentMonth = new Date().getMonth();
                    const allowedMonths = [currentMonth, currentMonth - 1, currentMonth - 2];
                    return !allowedMonths.includes(time.getMonth());
                },
            },
        }
    },
}
</script>

CSS代码:

css 复制代码
<style>
.el-month-table td .cell{
    background-color:unset !important;
}
</style>
相关推荐
萧曵 丶4 小时前
Vue 中父子组件之间最常用的业务交互场景
javascript·vue.js·交互
Amumu121385 小时前
Vue3扩展(二)
前端·javascript·vue.js
泓博7 小时前
Android中仿照View selector自定义Compose Button
android·vue.js·elementui
+VX:Fegn08957 小时前
计算机毕业设计|基于springboot + vue鲜花商城系统(源码+数据库+文档)
数据库·vue.js·spring boot·后端·课程设计
pas1368 小时前
45-mini-vue 实现代码生成三种联合类型
前端·javascript·vue.js
boooooooom10 小时前
Vue v-for + key 优化封神:吃透就地复用与强制重排,再也不卡帧!
javascript·vue.js·面试
程序猿_极客11 小时前
【2026】分享一套优质的 Php+MySQL的 校园二手交易平台的设计与实现(万字文档+源码+视频讲解)
vue.js·毕业设计·php·mysql数据库·二手交易系统
青屿ovo13 小时前
Vue2跨组件通信方案:全局事件总线与Vuex的灵活结合
前端·vue.js
赵_叶紫14 小时前
使用Cursor 完成 Vike + Vue 3 + Element Plus 管理后台 — 从 0 到 1 (实例与文档)
vue.js
harrain14 小时前
vue全局trycatch
前端·javascript·vue.js·firebug·trycatch