el-date-picker 只能选择当前时间一年前到今天的时间

本文介绍了如何在Vue的el-date-picker组件中实现时间范围选择器,特别关注了如何设置禁用日期,即不允许用户选择过去一年以前或未来的日期。
摘要由CSDN通过智能技术生成

当前时间2023-11-1

效果图:

直接上代码

//html

 <el-date-picker
    v-model="item.time"
    type="datetimerange"
    range-separator="至"
    start-placeholder="开始时间"
    end-placeholder="结束时间"
    style="width: 330px"
    size="mini"
    align="center"
    :pickerOptions="timeOption"
 />


//js

 data() {
    return {
      timeOption: {
        disabledDate: (time) => {
          const oneYearBefore = new Date(
            new Date().setFullYear(new Date().getFullYear() - 1)
          )
          console.log(oneYearBefore, 'oneYearBefore')
          console.log(new Date(), 'new Date()')
          return time > new Date() || time < oneYearBefore 
        },
      },
    }
  }

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值