vue更多筛选项小组件使用详解

2022-04-15 0 1,088

本文实例为大家分享了vue更多筛选项小组件的实现方法,供大家参考,具体内容如下

效果:

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

正常大屏

vue更多筛选项小组件使用详解

分辨率变小

vue更多筛选项小组件使用详解

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

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>

以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持NICE源码。

免责声明:
1、本网站所有发布的源码、软件和资料均为收集各大资源网站整理而来;仅限用于学习和研究目的,您必须在下载后的24个小时之内,从您的电脑中彻底删除上述内容。 不得使用于非法商业用途,不得违反国家法律。否则后果自负!

2、本站信息来自网络,版权争议与本站无关。一切关于该资源商业行为与www.niceym.com无关。
如果您喜欢该程序,请支持正版源码、软件,购买注册,得到更好的正版服务。
如有侵犯你版权的,请邮件与我们联系处理(邮箱:skknet@qq.com),本站将立即改正。

NICE源码网 JavaScript vue更多筛选项小组件使用详解 https://www.niceym.com/29310.html