vue更多筛选项小组件

vue更多筛选项小组件

效果:

就是一个简单的小效果,当有很多筛选条件时,默认只展示几项,不会觉得很冗余,有需要可以点击展开,进行更过的条件筛选。并且能够自动判断界面的尺寸,决定是否需要更多筛选项。直接把“查询、重置”内置到组件里面了,便于组件样式的实现,还可以进行插槽。

正常大屏

在这里插入图片描述

分辨率变小

在这里插入图片描述

可见出现了更多筛选的按钮,可以点击下拉

在这里插入图片描述

插槽

在这里插入图片描述

代码:
<template>
  <div :class="['colla-wrap']" ref="filter">
    <div class="colla-box" ref="filterCont" :style="maxWidth ? 'max-width:' + maxWidth: ''">
      <slot></slot>
    </div>
    <div class="ctrl">
      <div class="deal-b" >
        <el-button size="mini" type="primary" icon="el-icon-search" @click="clickSearch">查询</el-button>
        <el-button size="mini" plain icon="el-icon-refresh-left" @click="clickReset">重置</el-button>
        <slot name="moreBtns"></slot>
        <div class="deal-b" @click="showCollapse" v-if="autoExpend.more">
          <i class="el-icon-arrow-down turnDown" v-if="!autoExpend.collapseVisible"></i>
          <i class="el-icon-arrow-up turnUp" v-if="autoExpend.collapseVisible"></i>
          <div v-if="!autoExpend.collapseVisible" class="more-words">更多筛选项</div>
          <div v-if="autoExpend.collapseVisible" class="more-words">收起筛选</div>
        </div>
      </div>
    </div>
  </div>
</template>
<script>
export default={
	data(){
		return{
			  collapseData:{
			    collapseVisible:false
			  },
			  //自动折叠显示更多筛选项
			  autoExpend:{
			    more:false,
			    collapseVisible:false,
			    hasTop:false,
			    hasFilter:false
			  },
		}
	},
	props:['maxWidth'],
  mounted(){
    this.watchScrollHeight()
    window.addEventListener("resize", () => {
      this.watchScrollHeight()
    });
  },
  methods:{
    clickSearch(){
	    this.$emit('clickSearch')
	  },
	  clickReset(){
	    this.$emit('clickReset')
	  },
	  showCollapse(){
	    this.methods('showCollapse')
	  },
	  showCollapse(){
	    this.autoExpend.collapseVisible = !this.autoExpend.collapseVisible
	    this.$refs.filterCont.style.height = this.autoExpend.collapseVisible?'auto':'50px'
	  }
	
	  //尝试监控这个高度
	  watchScrollHeight(){
	    let filter = this.$refs.filter;
	    if(filter){
	      this.$nextTick(() => {
	        this.autoExpend.more = $(filter).find(".colla-box")[0].scrollHeight > 50;
	      })
	      
	    }
	    //判断下面有没有元素节点 决定这个插槽是否显示
	    //判断正常搜索框部位插槽
	    if(this.$refs.filterCont&&this.$refs.filterCont.childNodes.length){
	      this.autoExpend.hasFilter = true
	    }
	  }
  }
  
}
</script>
<style scoped lang="scss">
  .colla-wrap{
    width: 100%;
    .colla-box{
      max-width: calc(100% - 400px);
      float: left;
      box-sizing: border-box;
      overflow: hidden;
      height: 50px;
      >div,button{
        float: left;
        margin-right: 20px;
        margin-bottom: 20px;
      }
    }
    .ctrl{
      display: flex;
      align-items: flex-start;
      justify-content: flex-start;
      color: #409EFF;
      button{
        margin-right: 20px;
      }
      .deal-b{
        display: flex;
        align-items: flex-start;
        flex-wrap: nowrap;
        .deal-b{
          margin-right: 0;
          margin-bottom: 0;
          margin-top: 5px;
          display: flex;
          align-items: center;
          cursor: pointer;
          color: #409EFF;
          .more-words{
            min-width: 75px;
          }
          i{
            color: #409EFF;
            margin-right: 5px;
          }
        }
      }
    }
  }
</style>

  • 0
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 1
    评论
Vue 组合筛选可以通过多个筛选条件的组合来实现更精细的数据筛选。以下是一个简单的实现: 1. 在 Vue 组件中定义一个包含筛选条件的对象,例如: ```javascript data() { return { filters: { keyword: '', category: '', priceRange: '' }, products: [ { name: 'product1', category: 'category1', price: 10 }, { name: 'product2', category: 'category2', price: 20 }, { name: 'product3', category: 'category1', price: 30 }, { name: 'product4', category: 'category3', price: 40 }, { name: 'product5', category: 'category2', price: 50 }, ] } } ``` 2. 在模板中添加筛选条件的输入框和按钮,例如: ```html <div> <input type="text" v-model="filters.keyword" placeholder="search product"> <select v-model="filters.category"> <option value="">All Categories</option> <option value="category1">Category1</option> <option value="category2">Category2</option> <option value="category3">Category3</option> </select> <select v-model="filters.priceRange"> <option value="">All Prices</option> <option value="0-20">$0-$20</option> <option value="20-40">$20-$40</option> <option value="40-60">$40-$60</option> </select> <button @click="filterProducts">Filter</button> </div> ``` 3. 在组件中定义一个计算属性,用于根据筛选条件过滤数据,例如: ```javascript computed: { filteredProducts() { let products = this.products; if (this.filters.keyword) { products = products.filter(p => p.name.toLowerCase().includes(this.filters.keyword.toLowerCase())); } if (this.filters.category) { products = products.filter(p => p.category === this.filters.category); } if (this.filters.priceRange) { const [minPrice, maxPrice] = this.filters.priceRange.split('-'); products = products.filter(p => p.price >= minPrice && p.price <= maxPrice); } return products; } } ``` 4. 在模板中显示过滤后的数据,例如: ```html <div> <div v-for="product in filteredProducts" :key="product.name"> {{ product.name }} - {{ product.category }} - ${{ product.price }} </div> </div> ``` 这样就实现了一个基本的 Vue 组合筛选功能。你可以根据实际需求修改筛选条件和数据源。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

_小郑有点困了

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值