300字范文,内容丰富有趣,生活中的好帮手!
300字范文 > elementui 日期时间选择器 只能选择当前时间之后的时间

elementui 日期时间选择器 只能选择当前时间之后的时间

时间:2024-07-05 09:17:39

相关推荐

elementui 日期时间选择器 只能选择当前时间之后的时间

elementui 日期时间选择器 只能选择当前时间之后的时间

日期时间选择器禁止选择当前时间之前的时间,但是点击确认时是当前时间

前言

一、设置时间范围

<el-date-pickertype="datetime":picker-options="expireTimeOPtion"value-format="yyyy-MM-dd HH:mm:ss"placeholder="请选择截止时间"v-model="ruleForm.time"@focus="focus":default-value="defaultValue"></el-date-picker>

data(){return{expireTimeOPtion: {disabledDate(time) {return time.getTime() < Date.now() //如果没有后面的-8.64e7就是不可以选择今天的},},}}

二、去掉此刻按钮

focus() {this.$nextTick(() => {document.getElementsByClassName('el-button--text')[0].setAttribute('style','display:none')})}

我以为我这样可以了,但是当我不选择日期就点击确认的时候就会显示当前时间,所以为了避免这个问题便有了第三步,虽然不是什么好办法,但是能解决燃眉之急

三、设置默认值

data(){return{defaultValue:'',}}

created(){this.defaultValue =this.getTomorrowTime()}

// 获取明天时间getTomorrowTime() {const yy = new Date().getFullYear()const MM = new Date().getMonth() + 1 < 10? '0' + (new Date().getMonth() + 1): new Date().getMonth() + 1const dd = new Date().getDate() < 10 ? '0' + new Date().getDate() : new Date().getDate()const HH = new Date().getHours() < 10 ? '0' + new Date().getHours() : new Date().getHours()const mm = new Date().getMinutes() < 10 ? '0' + new Date().getMinutes() : new Date().getMinutes()const ss = new Date().getSeconds() < 10 ? '0' + new Date().getSeconds() : new Date().getSeconds()return yy + '-' + MM + '-' + (dd+1) + ' ' + HH + ':' + mm + ':' + ss},

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。