基于Vue实现的多条件筛选功能,可用于筛选商品之类的功能;

效果图:
在这里插入图片描述

<!--排序筛选-->
<div class="the-sorts" id="vue-sorts">
    <div class="pick-con">
        <div class="tablist">
            <ol class="sort-ol">
                <li class="tk" v-for="(v,index) in sorts" :class="{cur:v.isActive}" @click="changeTab(index)">
                    <span class="tt" v-cloak ref="chooseTitle">{{v.title}}</span>
                    <i class="i"></i>
                </li>
            </ol>
        </div>
        <div class="droplist" >
            <ul class="sort-ul" v-for="(v,index) in sorts"  v-show="v.isShow">
                <li class="tg" v-for="(c,index) in v.cidArr" :class="{cur:c.isChecked}" @click="chooseItem(index)">
                    <span class="ti" v-cloak>{{c.title}}</span>
                </li>
            </ul>
        </div>
    </div>
</div>
<script type="text/javascript">
    //vue排序筛选
    const vueSorts = new Vue({
        el: '#vue-sorts',
        data(){
            return{
                sorts:[], //排序列表
                curIndex:"0",   //切换栏当前索引值
                typeId:"1001",  //选择类型id
                followerId:"1001",  //粉丝量id
            }
        },
        created(){
            this.getSortJson();
        },
        methods:{
            //获取排序的数据
            getSortJson(){
                let url = 'json/sortTest.json';
                axios.get(url)
                    .then(response =>{
                    this.sorts = response.data.data;
                })
                .catch(error => {
                    console.log(error)
                })
            },

            //切换栏
            changeTab(index){
                let vm = this,
                    sorts = vm.sorts;
                this.curIndex = index;
                sorts.forEach((v,i)=>{
                    vm.$set(v, 'isActive', false);
                    if(index!==i){
                        vm.$set(v, 'isShow', false);
                    }
                })
                sorts[index].isActive = true;
                sorts[index].isShow = !sorts[index].isShow;
            },

            //选择选项
            chooseItem(index){
                let vm = this,
                    sorts = vm.sorts,
                    curIndex = vm.curIndex;
                sorts[curIndex].cidArr.forEach((c,k)=> {
                    c.isChecked = false;
                })
                sorts[curIndex].cidArr[index].isChecked = true;
                var chooseId = sorts[curIndex].cidArr[index].key,
                    chooseTitle = sorts[curIndex].cidArr[index].title;
                if(curIndex==0){
                    vm.typeId = chooseId;
                }else if(curIndex==1){
                    vm.followerId = chooseId;
                }
                vm.$refs.chooseTitle[curIndex].innerText = chooseTitle;
                sorts[curIndex].isShow = false;
            }
        }
    })
</script>

在这里插入图片描述

Logo

前往低代码交流专区

更多推荐