使用vue中的el-date-picker日期选择器,用户不手动选择时,默认显示当天日期和往后或者往前的时间

项目场景:

需要一些票据例如:电子发票这些时间,可以设置当前时间和往后或者往前某天的时间

原因分析:

使用了el-date-picker时间选择器,是可以选择时间但是无法显示之前或者之后的时间,我这个问题困扰我三天时间一直解决不出来,也试过很多办法,就是没有思路


解决方案:

js代码:

<el-form-item label="开方日期" prop="sheetDate">
                                    <el-date-picker  v-model="queryInfos.sheetDate" type="datetime" class="inputss" size="large" placeholder="开始日期">
                                    </el-date-picker>
                                </el-form-item>

<el-form-item label="结束日期" prop="endTime">
                                    <div class="block">
                                        <el-date-picker v-model="queryInfos.endTime" type="datetime" class="inputss" size="small" placeholder="开始日期"
                                         style="width: 100%;">
                                        </el-date-picker>
                                    </div>
                                </el-form-item>
                            </el-col>

methods: {
			  getdatatime(){  //默认显示今天
			      //this.queryInfos.sheetDate= new Date();
				  const currentDate = new Date()
				        const year = currentDate.getFullYear();
				        const month = currentDate.getMonth();
				        const date = currentDate.getDate();
				        const end = (new Date(year, month, date, 0,0,0)).getTime(); // 2021-12-24 00:00:00
				        const start = end + (3600 * 1000 * 24 * 3) 三天后 00:00:00
						this.queryInfos.sheetDate = end
				        this.queryInfos.endTime = start				  
			    },
}

mounted() {
		    let that = this;
		    that.getdatatime()
		  }

这些代码其实就是获取当前的年月日然后进行计算,根据自己的需求做好计算之后将对应的时间赋值到你对应的字段,然后在mounted() 里调用你这个方法就可以了
      

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值