溫馨提示×

您好,登錄后才能下訂單哦!

密碼登錄×
登錄注冊(cè)×
其他方式登錄
點(diǎn)擊 登錄注冊(cè) 即表示同意《億速云用戶服務(wù)條款》

Vue如何實(shí)現(xiàn)點(diǎn)擊時(shí)間獲取時(shí)間段查詢(xún)功能

發(fā)布時(shí)間:2021-04-23 12:59:24 來(lái)源:億速云 閱讀:385 作者:小新 欄目:web開(kāi)發(fā)

這篇文章將為大家詳細(xì)講解有關(guān)Vue如何實(shí)現(xiàn)點(diǎn)擊時(shí)間獲取時(shí)間段查詢(xún)功能,小編覺(jué)得挺實(shí)用的,因此分享給大家做個(gè)參考,希望大家閱讀完這篇文章后可以有所收獲。

vue是什么

Vue是一套用于構(gòu)建用戶界面的漸進(jìn)式JavaScript框架,Vue與其它大型框架的區(qū)別是,使用Vue可以自底向上逐層應(yīng)用,其核心庫(kù)只關(guān)注視圖層,方便與第三方庫(kù)和項(xiàng)目整合,且使用Vue可以采用單文件組件和Vue生態(tài)系統(tǒng)支持的庫(kù)開(kāi)發(fā)復(fù)雜的單頁(yè)應(yīng)用。

效果圖如下

Vue如何實(shí)現(xiàn)點(diǎn)擊時(shí)間獲取時(shí)間段查詢(xún)功能

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">查詢(xún)</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)擊查詢(xún)時(shí)間段效果就可以實(shí)現(xiàn)了。

關(guān)于“Vue如何實(shí)現(xiàn)點(diǎn)擊時(shí)間獲取時(shí)間段查詢(xún)功能”這篇文章就分享到這里了,希望以上內(nèi)容可以對(duì)大家有一定的幫助,使各位可以學(xué)到更多知識(shí),如果覺(jué)得文章不錯(cuò),請(qǐng)把它分享出去讓更多的人看到。

向AI問(wèn)一下細(xì)節(jié)

免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如果涉及侵權(quán)請(qǐng)聯(lián)系站長(zhǎng)郵箱:is@yisu.com進(jìn)行舉報(bào),并提供相關(guān)證據(jù),一經(jīng)查實(shí),將立刻刪除涉嫌侵權(quán)內(nèi)容。

vue
AI