vue 按条件筛选 坊商品

<template>

  <div>

    <div>

      <ul style="display:flex;">

        {{search}}

        <ul class="citys">城市:</ul>

        <ul class="citys" style="margin-left:10px;" v-for="(item,index,key) in city" :key="index+'st'"

          :class='{box2:index==activeindex}' @click='changeIndex(index,key)'>

          <ul>{{item.city}}</ul>

        </ul>

      </ul>

      <ul style="display:flex;margin-top:100px;">

        <ul class="citys">分类:</ul>

        <ul class="citys" style="margin-left:10px;" ref='geogra' v-for="(item,index) in geogra" :key="index+'1'"

          :class='{box2:index==activeindex1}' @click='changeIndex1(index)'>

          <ul>{{item.geogra}}</ul>

        </ul>

      </ul>

      <ul v-for="(item,index) in change" :key="index">

        <span>{{item.city}} </span>

        <ul>{{item.geogra}}</ul>

        <ul><img :src="item.img" alt=""></ul>

      </ul>

      <div v-if='s'>没有符合条件的数据</div>

    </div>

  </div>

</template>

<script>

  export default {

    name: 'filters',

    data() {

      return {

        s: false,

        activeindex: '',

        activeindex1: '',

        search: '',

        searchs: '',

        awm: '',

        arr: [],

        arrs: [],

        city: [{

            city: '全部'

          }, {

            city: '上海'

          },

          {

            city: '苏州'

          },

          {

            city: '杭州'

          },

          {

            city: '无锡'

          },

          {

            city: '大洋洲'

          },

        ],

        arrw: [],

        geogra: [{

            geogra: '类型'

          },

          {

            geogra: '相声'

          },

          {

            geogra: '说唱'

          },

          {

            geogra: '发布会'

          },

          {

            geogra: '演唱会'

          }

        ],

        cyties: {

          city: '',

          geogra: '',

        },

        list: [{

            id: 0,

            city: '上海',

            geogra: '演唱会',

            img: 'https://dss3.bdstatic.com/70cFv8Sh_Q1YnxGkpoWK1HF6hhy/it/u=2534506313,1688529724&fm=26&gp=0.jpg'

          },

          {

            id: 1,

            city: '上海',

            geogra: '发布会',

            img: 'https://dss3.bdstatic.com/70cFv8Sh_Q1YnxGkpoWK1HF6hhy/it/u=2534506313,1688529724&fm=26&gp=0.jpg'

          },

          {

            id: 2,

            city: '无锡',

            geogra: '发布会',

            img: 'https://dss1.bdstatic.com/70cFuXSh_Q1YnxGkpoWK1HF6hhy/it/u=3892521478,1695688217&fm=26&gp=0.jpg'

          },

          {

            id: 3,

            city: '苏州',

            geogra: '演唱会',

            img: 'https://dss1.bdstatic.com/70cFvXSh_Q1YnxGkpoWK1HF6hhy/it/u=4018557288,1217151095&fm=26&gp=0.jpg'

          },

          {

            id: 4,

            city: '杭州',

            geogra: '相声',

            img: 'https://dss2.bdstatic.com/70cFvnSh_Q1YnxGkpoWK1HF6hhy/it/u=3252521864,872614242&fm=26&gp=0.jpg'

          },

          {

            id: 5,

            city: '大洋洲',

            geogra: '说唱',

            img: 'https://dss0.bdstatic.com/70cFuHSh_Q1YnxGkpoWK1HF6hhy/it/u=1906469856,4113625838&fm=26&gp=0.jpg'

          },

        ]

      }

    },

    watch: {

      change(value) {

        if (value == '') {

          this.s = true

        } else {

          this.s = false

        }

      }

    },

    computed: {

      change() {

        return this.list.filter(item => {

          if (this.search == '全部' && this.searchs == '类型') {

            return this.list

          } else if (this.search == '全部' && JSON.stringify(item).indexOf(this.searchs) > -1) {

            return this.list

          } else if (JSON.stringify(item).indexOf(this.search) > -1 && this.searchs == '类型') {

            return this.list

          } else if (!this.search && !this.searchs) {

            return this.list

          } else if (JSON.stringify(item).indexOf(this.search) > -1 && !this.searchs) {

            return this.list

          } else if (JSON.stringify(item).indexOf(this.searchs) > -1 && !this.search) {

            return this.list

          } else if (item.geogra == this.searchs && item.city == this.search) {

            return this.list

          }

        })

      }


 

    },

    methods: {

      changeIndex(index) {

        let city = this.city

        this.search = city[index].city //获取城市地方

        this.activeindex = index

      },

      changeIndex1(index) {

        this.activeindex1 = index

        this.searchs = this.geogra[index].geogra

      },

    }

  }

</script>

<style lang="less" scoped>

  .city {

    display: flex;

  }


 

  .img {

    display: flex;

  }

  .citys {

    width: 100px;

    height: 50px;

    line-height: 50px;

    text-align: center;

  }

  .box2 {

    width: 100px;

    height: 50px;

    line-height: 50px;

    background: pink;

    color: #fff;

  }

</style>

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值