您好,登錄后才能下訂單哦!
基于Vue實現的多條件篩選功能(類似京東和淘寶功能),可以支持多選、清空、全選功能,數據源是通過JSon格式的數據封裝而成。
實現的效果圖:
代碼實現如下:
html:
<div id='app'> <template v-if='condition.length'> <div> <span>已選中:<span> <span v-for='(item,index) in condition' class='active'>{{item.name}} | </span> </div> </template> <template v-if='category.length'> <div class='nav' v-for='(items,index) in category'> <div class='mutil-query-title' v-if='items.name' :key="items.id">{{items.name}}<span style='margin-left: 20px;' @click='allIn(index)'>全選</span>|<span @click='remove(index)'>清空</span></div> <ol v-if='items.items.length'> <li v-for='(item,key) in items.items'> <span :class="{'active':item.active}" @click='handle(index,key)' :key='item.id'>{{item.name}}</span> </li> </ol> </div> </template> </div>
js代碼如下:
var list={ category:[ { name:'品牌', items:[ { name:'聯想', active: false }, { name:'小米', active: false }, { name:'蘋果', active: false }, { name:'東芝', active: false } ] }, { name:'CPU', items:[ { name:'intel i7 8700K', active: false }, { name:'intel i7 7700K', active: false }, { name:'intel i9 9270K', active: false }, { name:'intel i7 8700', active: false }, { name:'AMD 1600X', active: false } ] }, { name:'內存', items:[ { name:'七彩虹8G', active: false }, { name:'七彩虹16G', active: false }, { name:'金士頓8G', active: false }, { name:'金士頓16G', active: false } ] }, { name:'顯卡', items:[ { name:'NVIDIA 1060 8G', active: false }, { name:'NVIDIA 1080Ti 16G', active: false }, { name:'NVIDIA 1080 8G', active: false }, { name:'NVIDIA 1060Ti 16G', active: false } ] } ], condition:[ ] };
var count=0; var app =new Vue({ el:'#app', data:list, methods:{ handle:function(index,key){ var item=this.category[index].items; item.filter(function(v,i){ if(i==key){ v.active=true; this.list.condition.filter(function(v2,i){ if(v.name==v2.name){ this.list.condition.splice(i,1); count--; } }); Vue.set(this.list.condition,count++,v); } }); }, remove:function(index){ var item=this.category[index].items; item.filter(function (v1,key) { v1.active=false; this.list.condition.filter(function(v2,i){ if(v1.name==v2.name){ this.list.condition.splice(i,1); count--; } }); }); }, allIn:function(index){ var item=this.category[index].items; item.filter(function (v,key) { v.active=true; this.list.condition.filter(function(v2,i){ if(v.name==v2.name){ this.list.condition.splice(i,1); count--; } }); Vue.set(this.list.condition,count++,v); }); } } });
源碼地址:http://xz.jb51.net:81/201905/yuanma/mutilQuery(jb51.net).rar
以上所述是小編給大家介紹的Vue多條件篩選功能詳解整合,希望對大家有所幫助,如果大家有任何疑問請給我留言,小編會及時回復大家的。在此也非常感謝大家對億速云網站的支持!
免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。