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 小时前
VTJ.PRO AI Agent 技术白皮书
前端·vue.js·低代码
java1234_小锋6 小时前
Vue3专题 - 列表渲染
vue.js
小锋java12349 小时前
【技术专题】Vue3 - 列表渲染
vue.js·vite
zho_uzhou11 小时前
ubuntu服务端运行vue网页步骤
linux·服务器·vue.js·ubuntu
滴滴答答哒21 小时前
VUE3+element-plus MultiSelect 多选下拉组件
前端·javascript·vue.js
其美杰布-富贵-李21 小时前
04 watch 与 Vue 响应式数据流
前端·javascript·vue.js
其美杰布-富贵-李1 天前
03 ref、reactive 与 computed 响应式数据
前端·javascript·vue.js
嘟嘟07171 天前
useRef + Web Worker:React 中的耗时计算不卡页面
javascript·vue.js
万敏1 天前
Vue3 全栈实战第五周:Vitest 单元测试从零搭建实战记录
vue.js·node.js·全栈
sugar__salt1 天前
跟着 Demo 学 Pinia:两种仓库写法 + 完整 TodoList 复现
前端·javascript·vue.js·前端框架·vue