Vue实现点击时间获取时间段查询功能
二话不说,先上图
实现如上代码:
//获取本周第一天 showWeekFirstDay: function () { let Nowdate = new Date(); let WeekFirstDay = new Date(Nowdate - (Nowdate.getDay() - 1) * 86400000); let M = Number(WeekFirstDay.getMonth()) + 1; if (M < 10) { M = "0" + M; } let D = WeekFirstDay.getDate(); if (D < 10) { D = "0" + D; } return WeekFirstDay.getFullYear() + "-" + M + "-" + D; }, // 自动回填日期 autoTime(type) { this.active_time_type = type; switch (type) { case 1:
//今日 var temp_start_create_time = new Date().Format("yyyy-MM-dd"); var temp_end_create_time = new Date().Format("yyyy-MM-dd"); break; case 2:
//本周 var temp_start_create_time = this.showWeekFirstDay() var temp_end_create_time = new Date().Format("yyyy-MM-dd"); break; case 3:
//本月 var temp_start_create_time = util.getCurrentMonthFirst(); var temp_end_create_time = util.getCurrentMonthLast(); break; default: break; } this.value1 = []//element-ui 使用的日期控件定义的v-model值 this.value1.push(temp_start_create_time, temp_end_create_time) this.start_create_time = this.value1[0]; this.end_create_time = this.value1[1]; } }