vue如何通過日期篩選數(shù)據(jù)
如何通過日期篩選數(shù)據(jù)
此片博客介紹的方法是通過請求后臺數(shù)據(jù)給的狀態(tài),然后把自己選擇的時間傳過去實現(xiàn)篩選的,根據(jù)業(yè)務(wù)邏輯來參考吧!
下篇我們會說下通過vue過濾器來實現(xiàn)的方法!
業(yè)務(wù)邏輯:首先前端需要獲取其用戶選擇的日期數(shù)據(jù),然后通過接口把日期數(shù)據(jù)傳給后端,后端接收數(shù)據(jù)會返回給前端新的數(shù)據(jù),頁面在進行渲染。到此功能會是實現(xiàn)了
html部分
<div class="ag_listmain clearfix">?
? ? ? ? ? ? ? ? ? ? ? <div class="ag_yearlist" v-for="(item,key) in list" :key="key" @click="agrouter(item.id)">
? ? ? ? ? ? ? ? ? ? ? ? <div class="agtitle">
? ? ? ? ? ? ? ? ? ? ? ? ? ? <p>余額提現(xiàn)-到{{item.from_to}}</p>
? ? ? ? ? ? ? ? ? ? ? ? ? ? <label>{{item.created_at}}</label>
? ? ? ? ? ? ? ? ? ? ? ? </div>
? ? ? ? ? ? ? ? ? ? ? ? <div class="ag_money">
? ? ? ? ? ? ? ? ? ? ? ? ? ? ? <h4>{{item.money}}</h4>
? ? ? ? ? ? ? ? ? ? ? ? ? ? ? <label>提現(xiàn)成功</label>
? ? ? ? ? ? ? ? ? ? ? ? </div>
? ? ? ? ? ? ? ? ? ? </div>vant日期組件
?<van-popup ? ? ? ? ? v-model="show" ? ? ? ? ? position="bottom" ? ? ? ? > ? ? ? ? ? ?<van-datetime-picker ? ? ? ? ? ? v-model="currentDate" ? ? ? ? ? ? type="year-month" ? ? ? ? ? ? :min-date="minDate" ? ? ? ? ? ? :formatter="formatter" ? ? ? ? ? ? ?@confirm="confirm()" ? ? ? ? ? ? ?@cancel='cancel()' ? ? ? ? ? ? ? ? /> ? ? ? ? </van-popup>
js部分
return{
list:[] ,
datesed:"",
}
// 選擇事件后確定按鈕方法
confirm(){
this.show=false;
this.page = 1; //讓當前的頁面顯示第一頁。
this.dates = this.formatDate(this.currentDate,`yyyy${'年'}MM${'月'}`); //將日期轉(zhuǎn)化為時間值 在我的博客主頁能找到這關(guān)于這個的博客
this.datesed = this.formatDate(this.currentDate,'yyyy-MM'); //將日期轉(zhuǎn)化為時間值 在我的博客主頁能找到這關(guān)于這個的博客
this.list = []; // 讓當前循環(huán)的數(shù)據(jù)為空,因為我做的數(shù)據(jù)分頁是往里對堆數(shù)據(jù)的,
this.agplease(); //執(zhí)行請求數(shù)據(jù)方法
// console.log(this.datesed) //獲取時間值
},
//請求數(shù)據(jù)
agplease(){
this.axios.get('user/bill',{
params : {
state : 3, //傳參數(shù)
page:this.page,
page_size:8,
date : this.datesed, //后臺給的狀態(tài)等于你提交的時間數(shù)據(jù)。這樣就可以了,
}
}).then(res => {
// 下面嗎是我自己處理數(shù)據(jù)的方法,
if(res.data.code === 200){
let aglist = res.data.data; // 總數(shù)據(jù)
let arr = aglist.list; // 數(shù)據(jù)·列表作為循環(huán)
let page_size =this.aglist.page_size; // 每頁顯示條數(shù)
for(let i=0; i<arr.length; i++){
// console.log(this.list)
this.list.push(arr[i]);
}
console.log(this.list);
this.lastpage =aglist.total_page;
// 加載狀態(tài)結(jié)束
this.loading = false;
if(this.lastpage <= this.page){
this.finished = true;
}
this.page++;
// console.log(this.list);
}
})
}
上面的代碼希望對你有幫助,當然寫法有很多根據(jù)你們自己的風格去寫
vue簡單數(shù)據(jù)篩選
給大家分享一個簡單的用vue實現(xiàn)數(shù)據(jù)篩選的代碼,因為我下載了vue.js所以我是內(nèi)聯(lián)的,沒有下載的同學可以去下載一下vue 官網(wǎng)
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title></title>
</head>
<body>
<script src="../vue.js"></script>
<div id="app">
<input type="text" v-model="keyword"/>
<div class="box" v-for="item in flist" :key="item">
{{item}}
</div>
</div>
<script type="text/javascript">
new Vue({
el:"#app",
data:{
keyword:"",
list:["草莓","菠蘿","杏","李子","西瓜","木瓜","哈密瓜","山竹","櫻桃","香蕉","芒果"]
},
computed:{
flist(){
// 如果item(水果列表中變量的項)包含文字 this.keyword(搜索關(guān)鍵字)
// a.includes(b)如果a包含b就返回true
// 返回true當前水果·就保留
return this.list.filter(item=>item.includes(this.keyword))
}
}
})
</script>
</body>
</html>以上為個人經(jīng)驗,希望能給大家一個參考,也希望大家多多支持腳本之家。
相關(guān)文章
Vue技巧Element Table二次封裝實戰(zhàn)示例
這篇文章主要為大家介紹了Vue技巧Element Table二次封裝實戰(zhàn)示例,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進步,早日升職加薪2022-11-11
Vue實現(xiàn)動態(tài)添加或者刪除對象和對象數(shù)組的操作方法
這篇文章主要介紹了在Vue項目中實現(xiàn)動態(tài)添加或者刪除對象和對象數(shù)組的操作方法,本文通過實例代碼給大家介紹的非常詳細,具有一定的參考借鑒價值,需要的朋友可以參考下2018-09-09
Vue3?setup的注意點及watch監(jiān)視屬性的六種情況分析
這篇文章主要介紹了Vue3?setup的注意點及watch監(jiān)視屬性的六種情況,本文給大家介紹的非常詳細,對大家的學習或工作具有一定的參考借鑒價值,需要的朋友可以參考下2023-04-04

