vue更多篩選項小組件使用詳解
本文實例為大家分享了vue更多篩選項小組件的實現(xiàn)方法,供大家參考,具體內(nèi)容如下
效果:
就是一個簡單的小效果,當有很多篩選條件時,默認只展示幾項,不會覺得很冗余,有需要可以點擊展開,進行更過的條件篩選。并且能夠自動判斷界面的尺寸,決定是否需要更多篩選項。直接把“查詢、重置”內(nèi)置到組件里面了,便于組件樣式的實現(xiàn),還可以進行插槽。
正常大屏
分辨率變小
可見出現(xiàn)了更多篩選的按鈕,可以點擊下拉
插槽
代碼:
<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' } //嘗試監(jiān)控這個高度 watchScrollHeight(){ let filter = this.$refs.filter; if(filter){ this.$nextTick(() => { this.autoExpend.more = $(filter).find(".colla-box")[0].scrollHeight > 50; }) } //判斷下面有沒有元素節(jié)點 決定這個插槽是否顯示 //判斷正常搜索框部位插槽 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>
以上就是本文的全部內(nèi)容,希望對大家的學習有所幫助,也希望大家多多支持腳本之家。
- Vue.js實現(xiàn)多條件篩選、搜索、排序及分頁的表格功能
- vue分類篩選filter方法簡單實例
- vuejs通過filterBy、orderBy實現(xiàn)搜索篩選、降序排序數(shù)據(jù)
- 使用vue-router beforEach實現(xiàn)判斷用戶登錄跳轉(zhuǎn)路由篩選功能
- 基于Vue實現(xiàn)的多條件篩選功能的詳解(類似京東和淘寶功能)
- VUE實現(xiàn)移動端列表篩選功能
- ant-design-vue中的select選擇器,對輸入值的進行篩選操作
- vue input輸入框關(guān)鍵字篩選檢索列表數(shù)據(jù)展示
- vue實現(xiàn)前端列表多條件篩選
- Vue通過input篩選數(shù)據(jù)
相關(guān)文章
vue 解決computed修改data數(shù)據(jù)的問題
今天小編就為大家分享一篇vue 解決computed修改data數(shù)據(jù)的問題,具有很好的參考價值,希望對大家有所幫助。一起跟隨小編過來看看吧2019-11-11vue.nextTick()與setTimeout的區(qū)別及說明
這篇文章主要介紹了vue.nextTick()與setTimeout的區(qū)別及說明,具有很好的參考價值,希望對大家有所幫助,如有錯誤或未考慮完全的地方,望不吝賜教2024-03-03Vue3 + TypeScript 開發(fā)總結(jié)
本文直接上 Vue3 + TypeScript + Element Plus 開發(fā)的內(nèi)容,感興趣的話一起來看看吧2021-08-08