Vue實現(xiàn)點擊時間獲取時間段查詢功能
更新時間:2021年08月31日 15:28:11 作者:cdx1170776994
這篇文章主要為大家詳細介紹了Vue實現(xiàn)點擊時間獲取時間段查詢功能,文中示例代碼介紹的非常詳細,具有一定的參考價值,感興趣的小伙伴們可以參考一下
本文實例為大家分享了vue按時間段查詢的案例,效果圖如下

html代碼
<template>
<div class="personalReport_time">
<input type="date" :max="this.endTime" value="" v-model="startTime"/>
<div></div>
<input type="date" :min="startTime" :max="this.maxTime" v-model="endTime"/>
</div>
<ul class="personalReport_date">
<li @click="query('today')">今天</li>
<li @click="query('yesterday')">昨天</li>
<li @click="query('weeks')">本周</li>
<li @click="query('lastWeek')">上周</li>
<li @click="query('month')">本月</li>
<li @click="query('lastMonth')">上月</li>
</ul>
<div>
<button @click="query" class="but">查詢</button>
</div>
</template>
vue.js代碼 點擊事件
//獲取時間、
//時間解析;
Time:function(now) {
let year=new Date(now).getFullYear();
let month=new Date(now).getMonth()+1;
let date=new Date(now).getDate();
if (month < 10) month = "0" + month;
if (date < 10) date = "0" + date;
return year+"-"+month+"-"+date
},
//本周第一天;
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;
},
//本周最后一天
showWeekLastDay:function ()
{
let Nowdate=new Date();
let WeekFirstDay=new Date(Nowdate-(Nowdate.getDay()-1)*86400000);
let WeekLastDay=new Date((WeekFirstDay/1000+6*86400)*1000);
let M=Number(WeekLastDay.getMonth())+1;
if(M<10){
M="0"+M;
}
let D=WeekLastDay.getDate();
if(D<10){
D="0"+D;
}
return WeekLastDay.getFullYear()+"-"+M+"-"+D;
},
//獲得某月的天數(shù):
getMonthDays:function (myMonth){
let monthStartDate = new Date(new Date().getFullYear(), myMonth, 1);
let monthEndDate = new Date(new Date().getFullYear(), myMonth + 1, 1);
let days = (monthEndDate - monthStartDate)/(1000 * 60 * 60 * 24);
return days;
},
//點擊事件
query:function (way) {
let self=this;
this.$refs.pag.currentPage=1;
this.page=this.$refs.pag.currentPage;
switch (way){
case 'today':
this.startTime=this.maxTime;
this.endTime=this.maxTime;
break;
case 'yesterday':
this.startTime=this.Time(new Date().getTime()-24*60*60*1000);
this.endTime=this.Time(new Date().getTime()-24*60*60*1000);
break;
case 'weeks':
this.startTime=this.showWeekFirstDay();
this.endTime=this.maxTime;
break;
case 'lastWeek':
this.startTime=this.Time(new Date(new Date().getFullYear(), new Date().getMonth(), new Date().getDate()-new Date().getDay()-6));
this.endTime=this.Time(new Date(new Date().getFullYear(), new Date().getMonth(), new Date().getDate()+(6-new Date().getDay()-6)));
break;
case 'month':
this.startTime=this.Time(new Date(new Date().getFullYear(), new Date().getMonth(),1));
this.endTime=this.maxTime;
break;
case 'lastMonth':
this.startTime=this.Time(new Date(new Date().getFullYear(),new Date().getMonth()-1,1));
this.endTime=this.Time(new Date(new Date().getFullYear(),new Date().getMonth()-1,this.getMonthDays(new Date().getMonth()-1)));
break;
}
this.$axios({
method:'post',
url:'/inter/user/queryMemberReport',
data:{
'account':this.account,
'baseLotteryId':this.lottersId,
'startTime':this.startTime,
'endTime':this.endTime
}
}).then(function (data) {
// console.log(data)
}).catch(function (error) {
console.log(error);
})
}
這樣一個點擊查詢時間段效果就可以實現(xiàn)了。
以上就是本文的全部內容,希望對大家的學習有所幫助,也希望大家多多支持腳本之家。
相關文章
Element-UI表格嵌入popover遇到的問題及解決方案
在表格中我們通常需要在每一行的一些單元格中顯示popover,這篇文章主要給大家介紹了關于Element-UI表格嵌入popover遇到的問題及解決方案,需要的朋友可以參考下2023-11-11
vue input輸入框關鍵字篩選檢索列表數(shù)據(jù)展示
這篇文章主要為大家詳細介紹了vue input輸入框關鍵字篩選檢索列表數(shù)據(jù)展示,文中示例代碼介紹的非常詳細,具有一定的參考價值,感興趣的小伙伴們可以參考一下2019-05-05
使用websocket和Vue2中的props實時更新數(shù)據(jù)方式
這篇文章主要介紹了使用websocket和Vue2中的props實時更新數(shù)據(jù)方式,具有很好的參考價值,希望對大家有所幫助,如有錯誤或未考慮完全的地方,望不吝賜教2024-08-08
基于Vue2.0+ElementUI實現(xiàn)表格翻頁功能
Element UI 是一套采用 Vue 2.0 作為基礎框架實現(xiàn)的組件庫,它面向企業(yè)級的后臺應用,能夠幫助你快速地搭建網(wǎng)站,極大地減少研發(fā)的人力與時間成本。這篇文章主要介紹了Vue2.0+ElementUI實現(xiàn)表格翻頁功能,需要的朋友可以參考下2017-10-10
vue-cli2與vue-cli3在一臺電腦共存的實現(xiàn)方法
這篇文章主要介紹了vue-cli2與vue-cli3在一臺電腦共存的實現(xiàn)方法,文中通過示例代碼介紹的非常詳細,對大家的學習或者工作具有一定的參考學習價值,需要的朋友們下面隨著小編來一起學習學習吧2019-09-09
詳解Vue 數(shù)據(jù)更新了但頁面沒有更新的 7 種情況匯總及延伸總結
這篇文章主要介紹了詳解Vue 數(shù)據(jù)更新了但頁面沒有更新的 7 種情況匯總及延伸總結,文中通過示例代碼介紹的非常詳細,對大家的學習或者工作具有一定的參考學習價值,需要的朋友們下面隨著小編來一起學習學習吧2020-05-05

