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>
相关推荐
Lee川10 小时前
从“DOM 操作”到“数据驱动”:Vue 如何重塑前端开发思维
前端·vue.js
sibylyue11 小时前
Typescritpt、ES6
前端·javascript·vue.js
sxq11 小时前
Flow Render: 像调用异步函数一样渲染 UI 组件
vue.js·react.js
小小程序员mono11 小时前
JS 与 Vue Router 导航方式对比
开发语言·javascript·vue.js
李剑一12 小时前
解决 Cesium 网络卡顿!5 分钟加载天地图,内网也能流畅用,附完整代码
前端·vue.js·cesium
肉肉不吃 肉12 小时前
Vue Router 路由模式
前端·javascript·vue.js
北寻北爱12 小时前
Vue-Router
前端·javascript·vue.js
天天向上102412 小时前
vue 页面内实现el-table和div自动滚动
前端·javascript·vue.js
wing9813 小时前
用 AI 实现图片懒加载,这也太简单了!
前端·vue.js·图片资源
前端小菜鸟也有人起13 小时前
Vue2父子组件通信方法总结
javascript·vue.js·ecmascript