本篇文章为大家展示了vue如何实现前端列表多条件筛选,内容简明扼要并且容易理解,绝对能使你眼前一亮,通过这篇文章的详细介绍希望你能有所收获。
1、先上图:
2、搜索条件绑定的数据是:
filterForm:{
schoolName:'',//输入的学校名称
position:'',//选择的区域区域
schoolLevel:"",//选择的学校办别
},
schoolList:[
{schoolName:'青岛市实验高级中学',schoolLevel:"",position:'山东省青岛市城阳区硕阳路69号'},
{schoolName:'山东省青岛第二中学',schoolLevel:"",position:'山东省青岛市崂山区松岭路70号'},
{schoolName:'山东省青岛第一中学',schoolLevel:"",position:'山东省青岛市市南区单县路46号'},
{schoolName:'山东省青岛第三十九中学',schoolLevel:"",position:'市南区登州路5号'},
{schoolName:'山东省青岛第六中学',schoolLevel:"",position:'山东省青岛市黄岛区云台山路66号'},
{schoolName:'山东省青岛第十九中学',schoolLevel:"",position:'山东省青岛市即墨区鳌山卫街道卫场路69号'},
{schoolName:'青岛艺术学校',schoolLevel:"",position:'青岛市李沧区九水路176号'},
{schoolName:'山东省青岛第九中学',schoolLevel:"",position:'山东省青岛市黄岛区七星河路559号'},
{schoolName:'青岛电子学校',schoolLevel:"",position:'山东省青岛市市北区台东一路118号'}
],//其中schoolList是元数据
resull:[]//搜索结果,也是列表循环的数据
3、监听:
watch: {
// 监听对象变化
filterForm:{
handler(val, oldVal){
if(val){
// 如果筛选条件全为空,查全部;否则按条件筛选
var objIsEmpty = this.filterForm.schoolName == '' && this.filterForm.schoolLevel == '' && this.filterForm.position == ''
if(objIsEmpty){
this.result = this.schoolList
} else {
// /拿到有值的参数
let tempFilter = {};
for(var key in this.filterForm) {
if(typeof(this.filterForm[key]) != "undefined" && typeof(this.filterForm[key]) != "null" && this.filterForm[key] != null && this.filterForm[key] != "") {
tempFilter[key] = this.filterForm[key];
}
}
// console.log(tempFilter,'输出tempFilter')
this.result = this.schoolList.filter(
//筛选
(item) => {
let flag = false;
for(key in tempFilter) {
console.log(key,'输出key')
if(item[key].toString().indexOf(tempFilter[key].toString()) >= 0) {
flag = true;
} else {
flag = false;
break;
}
}
if(flag) {
return item;
}
}
);
console.log(this.result,'输出筛选结果')
}
}
},
deep:true
}
}
上述内容就是vue如何实现前端列表多条件筛选,你们学到知识或技能了吗?如果还想学到更多技能或者丰富自己的知识储备,欢迎关注亿速云行业资讯频道。
亿速云「云服务器」,即开即用、新一代英特尔至强铂金CPU、三副本存储NVMe SSD云盘,价格低至29元/月。点击查看>>
免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。