Vue實(shí)現(xiàn)點(diǎn)擊時(shí)間獲取時(shí)間段查詢功能
本文實(shí)例為大家分享了vue按時(shí)間段查詢的案例,效果圖如下

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代碼 點(diǎn)擊事件
//獲取時(shí)間、
//時(shí)間解析;
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;
},
//點(diǎn)擊事件
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);
})
}
這樣一個(gè)點(diǎn)擊查詢時(shí)間段效果就可以實(shí)現(xiàn)了。
以上就是本文的全部?jī)?nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。
相關(guān)文章
vue實(shí)現(xiàn)微信分享朋友圈,發(fā)送朋友的示例講解
下面小編就為大家分享一篇vue實(shí)現(xiàn)微信分享朋友圈,發(fā)送朋友的示例講解,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。一起跟隨小編過(guò)來(lái)看看吧2018-02-02
vue使用axios訪問(wèn)本地json文件404問(wèn)題及解決
這篇文章主要介紹了vue使用axios訪問(wèn)本地json文件404問(wèn)題及解決,具有很好的參考價(jià)值,希望對(duì)大家有所幫助,如有錯(cuò)誤或未考慮完全的地方,望不吝賜教2024-07-07
Vue?+?Element?實(shí)現(xiàn)按鈕指定間隔時(shí)間點(diǎn)擊思路詳解
這篇文章主要介紹了Vue?+?Element?實(shí)現(xiàn)按鈕指定間隔時(shí)間點(diǎn)擊,實(shí)現(xiàn)思路大概是通過(guò)加一個(gè)本地緩存的時(shí)間戳,通過(guò)時(shí)間戳計(jì)算指定時(shí)間內(nèi)不能點(diǎn)擊按鈕,具體實(shí)現(xiàn)代碼跟隨小編一起看看吧2023-12-12
Vue.js實(shí)戰(zhàn)之使用Vuex + axios發(fā)送請(qǐng)求詳解
這篇文章主要給大家介紹了關(guān)于Vue.js使用Vuex與axios發(fā)送請(qǐng)求的相關(guān)資料,文中介紹的非常詳細(xì),相信對(duì)大家具有一定的參考價(jià)值,需要的朋友們下面來(lái)一起看看吧。2017-04-04
vue 單頁(yè)應(yīng)用和多頁(yè)應(yīng)用的優(yōu)劣
這篇文章主要介紹了vue 單頁(yè)應(yīng)用和多頁(yè)應(yīng)用的優(yōu)劣,幫助大家更好的理解和使用vue,感興趣的朋友可以了解下2020-10-10

