TypechoJoeTheme

香草物语

统计
登录
用户名
密码
/
注册
用户名
邮箱
输入密码
确认密码

el-datepicker设置可选日期范围

Laughing博主
2021-01-04
/
0 评论
/
1,466 阅读
/
76 个字
/
提交给度娘
01/04
本文最后更新于2022年11月20日,已超过667天没有更新。如果文章内容或图片资源失效,请留言反馈,我会及时处理,谢谢!

1.只能选择当前及以后的日期

<el-date-picker
       v-model="value1"
       type="date"
       :picker-options="pickerOptions">
</el-date-picker>

 data() {
        return {
            pickerOptions: {
                disabledDate(time) {
                    return time.getTime() < Date.now() - 8.64e7;
                }
            },
}

2.只能选择今天以及今天以前的日期

data (){
   return {
       pickerOptions: {
          disabledDate(time) {
            return time.getTime() > Date.now() - 8.64e6
          }
        }, 
   }    
}

3.只能选择今天之后的日期

data (){
   return {
       pickerOptions: {
          disabledDate(time) {
            return time.getTime() < Date.now();
          }
        },  
   }     
}

4.只能选择今天之前的日期

data (){
   return {
       pickerOptions0: {
          disabledDate(time) {
            return time.getTime() > Date.now();
          }
        },  
   }     
}

5.设置选择三个月之前到今天的日期

data (){
   return {
       pickerOptions0: {
          disabledDate(time) {
            let curDate = (new Date()).getTime();
            let three = 90 * 24 * 3600 * 1000;
            let threeMonths = curDate - three;
            return time.getTime() > Date.now() || time.getTime() < threeMonths;;
          }
        }, 
   }    
}

组件代码

<el-date-picker
       v-model="value1"
       type="date"
       placeholder="开始日期"
       :picker-options="pickerOptions0">
</el-date-picker>
<el-date-picker
       v-model="value2"
       type="date"
       placeholder="结束日期"
       :picker-options="pickerOptions1">
</el-date-picker>
Element UI
朗读
赞(2)
赞赏
感谢您的支持,我会继续努力哒!
版权属于:

香草物语

本文链接:

https://www.xiangcaowuyu.net/web/el-datepicker-sets-the-optional-date-range.html(转载时请注明本文出处及文章链接)

评论 (0)
  1. parksungjoe 闲逛
    Windows 10 · Google Chrome

    kankan 在学习呢

    2018-09-24 回复