项目场景:

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

原因分析:

使用了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() 里调用你这个方法就可以了
      

Logo

为开发者提供学习成长、分享交流、生态实践、资源工具等服务,帮助开发者快速成长。

更多推荐