vue更多篩選項(xiàng)小組件使用詳解
本文實(shí)例為大家分享了vue更多篩選項(xiàng)小組件的實(shí)現(xiàn)方法,供大家參考,具體內(nèi)容如下
效果:
就是一個(gè)簡(jiǎn)單的小效果,當(dāng)有很多篩選條件時(shí),默認(rèn)只展示幾項(xiàng),不會(huì)覺(jué)得很冗余,有需要可以點(diǎn)擊展開,進(jìn)行更過(guò)的條件篩選。并且能夠自動(dòng)判斷界面的尺寸,決定是否需要更多篩選項(xiàng)。直接把“查詢、重置”內(nèi)置到組件里面了,便于組件樣式的實(shí)現(xiàn),還可以進(jìn)行插槽。
正常大屏

分辨率變小

可見出現(xiàn)了更多篩選的按鈕,可以點(diǎ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">更多篩選項(xiàng)</div>
<div v-if="autoExpend.collapseVisible" class="more-words">收起篩選</div>
</div>
</div>
</div>
</div>
</template>
<script>
export default={
data(){
return{
collapseData:{
collapseVisible:false
},
//自動(dòng)折疊顯示更多篩選項(xiàng)
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)控這個(gè)高度
watchScrollHeight(){
let filter = this.$refs.filter;
if(filter){
this.$nextTick(() => {
this.autoExpend.more = $(filter).find(".colla-box")[0].scrollHeight > 50;
})
}
//判斷下面有沒(méi)有元素節(jié)點(diǎn) 決定這個(gè)插槽是否顯示
//判斷正常搜索框部位插槽
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>
以上就是本文的全部?jī)?nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。
- Vue.js實(shí)現(xiàn)多條件篩選、搜索、排序及分頁(yè)的表格功能
- vue分類篩選filter方法簡(jiǎn)單實(shí)例
- vuejs通過(guò)filterBy、orderBy實(shí)現(xiàn)搜索篩選、降序排序數(shù)據(jù)
- 使用vue-router beforEach實(shí)現(xiàn)判斷用戶登錄跳轉(zhuǎn)路由篩選功能
- 基于Vue實(shí)現(xiàn)的多條件篩選功能的詳解(類似京東和淘寶功能)
- VUE實(shí)現(xiàn)移動(dòng)端列表篩選功能
- ant-design-vue中的select選擇器,對(duì)輸入值的進(jìn)行篩選操作
- vue input輸入框關(guān)鍵字篩選檢索列表數(shù)據(jù)展示
- vue實(shí)現(xiàn)前端列表多條件篩選
- Vue通過(guò)input篩選數(shù)據(jù)
相關(guān)文章
vue 解決computed修改data數(shù)據(jù)的問(wèn)題
今天小編就為大家分享一篇vue 解決computed修改data數(shù)據(jù)的問(wèn)題,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。一起跟隨小編過(guò)來(lái)看看吧2019-11-11
vue.nextTick()與setTimeout的區(qū)別及說(shuō)明
這篇文章主要介紹了vue.nextTick()與setTimeout的區(qū)別及說(shuō)明,具有很好的參考價(jià)值,希望對(duì)大家有所幫助,如有錯(cuò)誤或未考慮完全的地方,望不吝賜教2024-03-03
簡(jiǎn)單說(shuō)說(shuō)如何使用vue-router插件的方法
這篇文章主要介紹了如何使用vue-router插件的方法,文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來(lái)一起學(xué)習(xí)學(xué)習(xí)吧2019-04-04
watch里面的deep和immediate作用及說(shuō)明
這篇文章主要介紹了watch里面的deep和immediate作用及說(shuō)明,具有很好的參考價(jià)值,希望對(duì)大家有所幫助,如有錯(cuò)誤或未考慮完全的地方,望不吝賜教2024-08-08
Vue3 + TypeScript 開發(fā)總結(jié)
本文直接上 Vue3 + TypeScript + Element Plus 開發(fā)的內(nèi)容,感興趣的話一起來(lái)看看吧2021-08-08

