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>
相关推荐
独泪了无痕2 小时前
viewer.js 安装与配置指南:实现图片预览功能
前端·vue.js
lemon_yyds10 小时前
uVIew2 弹框滚动穿透问题-[uu-popup ]组件
vue.js
超爱吃香菜的菜鸟11 小时前
关于pnpm 部分使用(一)
前端·vue.js
jingchao199815 小时前
Cannot read properties of null (reading ‘insertBefore‘)
前端·javascript·vue.js
猫不易1 天前
从 Virtual DOM 到 Vapor:Vue 3.6 的另一条路
前端·vue.js
岁岁种桃花儿1 天前
Vue核心语法第十二篇:条件渲染
前端·javascript·vue.js
雪碧聊技术1 天前
Vue + Element Plus 实现文本溢出显示省略号及悬浮提示
前端·javascript·css·vue.js·文本溢出省略
Highcharts.js2 天前
Highcharts 主流前端框架无缝集成指南
前端·vue.js·前端框架·highcharts·可视化图表
岁岁种桃花儿2 天前
Vue核心语法第十一篇:绑定样式
前端·javascript·vue.js
大龄码农有梦想2 天前
Vue + BPMN.js + Camunda:搭建企业级流程设计器完整实践
javascript·vue.js·流程设计器·bpmn.js·bpmn·流程审批·工作流设计器