element日期选择器只显示开始日期结束日期之间的日期

该代码片段展示了如何在Vue.js应用中使用ElementUI的日期选择器组件(el-date-picker)。它创建了一个日期范围选择器(daterange)并关联到`form.planDate`,然后根据选定的日期范围动态禁用日期选择器(fillTime)中的日期,确保选择的日期在开始和结束日期之间。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >


        <el-form-item label="开始结束日期" prop="planDate">
          <el-date-picker value-format="yyyy-MM-dd" v-model="form.planDate" style="width: 90%;" type="daterange"
            range-separator="" start-placeholder="开始日期" end-placeholder="结束日期" :clearable="false">
          </el-date-picker>
        </el-form-item>
        <el-form-item label="开始结束日期之间的日期" prop="fillTime">
          <el-date-picker v-model="form.fillTime" :picker-options="pickerOptions" value-format="yyyy-MM-dd" type="date"
            placeholder="请选择日期" style="width: 90%;"  >
          </el-date-picker>
        </el-form-item>
  data() {
    return {
      form: {
        planDate: [],
        fillTime:null,
      },
       pickerOptions: {
        disabledDate: (time) => {
          if (this.form.planDate.length !== 0) {
            const start = new Date(Number(this.form.planDate[0].split('-')[0]), Number(this.form.planDate[0].split('-')[1]) - 1, Number(this.form.planDate[0].split('-')[2])); // 月份从0开始计算,所以5月要写成4月
            const end = new Date(Number(this.form.planDate[1].split('-')[0]), Number(this.form.planDate[1].split('-')[1]) - 1, Number(this.form.planDate[1].split('-')[2]));;
            return time.getTime() < start.getTime() || time.getTime() > end.getTime();
          } else {
            return time.getTime()
          }
        }
      },
	}
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值