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>
相关推荐
这个一个非常哈3 小时前
VUE篇之自定义组件使用v-model
前端·javascript·vue.js
热爱前端的小君同学3 小时前
长按拖拽移动的vue3组件
前端·javascript·vue.js
noravinsc4 小时前
InforSuite AS 可以发布django和vue项目是否可行
vue.js·python·django
岁岁岁平安4 小时前
Vue3学习(组合式API——reactive()和ref()函数详解)
前端·javascript·vue.js·学习·vue3·reactive·ref
CUIYD_19894 小时前
javascript —— ! 和 !! 的区别与作用
前端·javascript·vue.js
慌糖5 小时前
vue3搭建脚手架前的前置知识
vue.js
海上彼尚8 小时前
秒删node_modules[无废话版]
vue.js·react.js
不爱吃饭爱吃菜11 小时前
uniapp微信小程序-长按按钮百度语音识别回显文字
前端·javascript·vue.js·百度·微信小程序·uni-app·语音识别
GoodStudyAndDayDayUp12 小时前
gitlab+portainer 实现Ruoyi Vue前端CI/CD
前端·vue.js·gitlab
前端 贾公子12 小时前
uniapp -- 验证码倒计时按钮组件
前端·vue.js·uni-app