项目场景:

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

原因分析:

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

解决方案:

js代码:

                                                                                                          

                                    

                                                                                                                      
                                                             

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

精彩链接

评论可见,请评论后查看内容,谢谢!!!评论后请刷新页面。