最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

ElementUI實(shí)現(xiàn)在下拉列表里面進(jìn)行搜索功能詳解

 更新時(shí)間:2023年04月01日 15:28:09   作者:寒墨茗殤  
有時(shí)候需要用到下拉列表全選和搜索,下面這篇文章主要給大家介紹了關(guān)于ElementUI實(shí)現(xiàn)在下拉列表里面進(jìn)行搜索功能的相關(guān)資料,文中通過(guò)實(shí)例代碼介紹的非常詳細(xì),需要的朋友可以參考下

分析:

  1. 首先我們需要實(shí)現(xiàn)上圖的效果,然后Element-UI的el-select是沒(méi)有的,所以需要自己寫(xiě)
  2. 我們需要用到el-popover組件,然后使用它的v-model="visible"來(lái)實(shí)現(xiàn)控制顯示
  3. 我們?cè)趀l-popover的slot="reference" 放一個(gè)el-select
    1. 使用popper-append-to-body="false"不需要插入浮動(dòng)元素
    2. 使用popper-class="hide-popper"定義浮窗class為hide-popper,并設(shè)置display:none,這樣選中了就不會(huì)存在el-select的下拉選項(xiàng)
    3. el-option 循環(huán)下面選擇的list里面的元素,這樣就可以在el-select展示選中的并存在刪除
    4. el-select雙向綁定的就是自定義選擇的數(shù)組

html:

<template>
	<div class="arrbox">
		<!-- 通過(guò)visible控制顯示還是隱藏 -->
		<el-popover
		v-model="visible"
		placement="bottom-start"
		width="auto"
		>
		<div slot="reference" class="check-select">
			<!-- popper-append-to-body:不需要插入浮動(dòng)元素,popper-class:設(shè)置類(lèi)名并隱藏 -->
			<el-select
			ref="select"
			v-model="currentval"
			:style="{width:`${width}px`,height:`${height}`}"
			multiple
			:placeholder="placeholder"
			:popper-append-to-body="false"
			popper-class="hide-popper"
			style="width:100%"
			@visible-change="visibleChange"
			@focus="getFocus"
			> <el-option
			v-for="item in selectItem"
			:key="`${item.value}_k`"
			:label="item.label"
			:value="item.value"
			/></el-select>
		</div>
		<!-- selectBxClick讓select強(qiáng)制選中 -->
		<div class="selectMain" :style="{'min-width':`${width-20}px`}" @click="selectBxClick">
			<div class="seachButton">
			<el-select
				v-model="seachValue"
				placeholder=" 請(qǐng)選擇篩選"
				style="width:70%;margin-right:10px;max-width:195px"
				@visible-change="selectBxClick()"
			>
				<el-option
				v-for="item in seachList"
				:key="item.value"
				:value="item.value"
				:label="item.label"
				/>
			</el-select>
			<div class="btn" @click="seachBtn">搜索</div>
			</div>
			 <div class="selectDiv">
                              <div v-for="item in list.filter(n=>n.value=='all')" :key="item.value" class="list" :class="[currentval.indexOf(item.value)!=-1?'selected':'',item.value=='all'?'allCheck':'']" @click="clickItem(item)">{{ item.label }}</div>

                              <div class="selectDivAuto">
                                <div v-for="item in list.filter(n=>n.value!='all')" :key="item.value" class="list" :class="[currentval.indexOf(item.value)!=-1?'selected':'',item.value=='all'?'allCheck':'']" @click="clickItem(item)">{{ item.label }}</div>
                              </div>

                            </div>
		</div>
		</el-popover>
	</div>
	</template>

js:

使用getFocus獲取是否聚焦,聚焦了讓visible=true,這樣就可以顯示出自定義的下拉選擇項(xiàng)

通過(guò)visibleChange實(shí)施監(jiān)聽(tīng)el-select,控制el-popover顯示

在點(diǎn)擊自定義的下拉選擇項(xiàng)時(shí),通過(guò)@click="selectBxClick"el-select一直聚焦,這樣箭頭就會(huì)一直向上

通過(guò) @click="seachBtn"getList獲取列表,具體需要自己去自定義

// 模擬獲取的數(shù)據(jù)
	const seachClickList = [{value: '1',label: '測(cè)試1',type: '1'},{value: '2',label: '測(cè)試2',type: '1'},{value: '3',label: '測(cè)試3',type: '1'},{value: '4',label: '測(cè)試4',type: '2'},{value: '5',label: '測(cè)試5',type: '2'},{value: '6',label: '測(cè)試6',type: '2'},{value: '7',label: '測(cè)試7',type: '2'}]
	export default {
	model: {
		prop: 'parentArr',
		event: 'change-parentArr'
	},
	props: {
		parentArr: {
		type: Array,
		default() {
			return []
		}
		},
		// 傳入選中的item,主要時(shí)防止list里面沒(méi)有選中的數(shù)據(jù)
		parentSelectItem: {
		type: Array,
		default() {
			return []
		}
		},
		width: {
		type: Number,
		default: 300
		},
		height: {
		type: Number,
		default: 30
		},
		placeholder: {
		type: String,
		default: '請(qǐng)輸入'
		}
	},
	data() {
		return {
		seachList: [
			{
			value: '1',
			label: '條件一'
			},
			{
			value: '2',
			label: '條件二'
			}
		],
		visible: false,
		currentval: [],
		list: [],
		selectItem: [],
		seachValue: '1'
		}
	},
	watch: {
		seachValue: {
		handler(value) {
			this.getList(value)
		},
		deep: true,
		immediate: true
		},
		parentArr: {
		handler(value) {
			this.currentval = value
		},
		deep: true,
		immediate: true
		},
		parentSelectItem: {
		handler(value) {
			this.selectItem =  value.map(n => {
                              if (n.value == 'all') {
                                n.label = '全部'
                              }
                              return n
                            })
		},
		deep: true,
		immediate: true
		},
		currentval: {
                        handler(value) {
                                this.$emit('change-parentArr', value)
                        }
		}
	},
	created() {
	},
	methods: {
		getList(value) {
                        this.list = [{
                                label: '全部',
                                value: 'all'
                        }, ...seachClickList.filter(n => n.type == value)]
                        this.getSelectItem()
		},
		// 獲取選中的item
		getSelectItem() {
                        const noItemList = this.currentval.map(n => {
                                if (this.selectItem.findIndex(i => i.value == n) == -1) {
                                return n
                                }
                                return null
                        }).filter(n => n != null)
                        noItemList.forEach(item => {
                                const index = this.list.findIndex(i => i.value == item)
                                if (index != -1) {
                                this.selectItem.push(this.list[index])
                                }
                        })
		},
		getFocus() {
                        this.visible = true
		},
		visibleChange(data) {
                        this.visible = data
		},
		selectBxClick() {
                        // 避免點(diǎn)擊框體時(shí)組件消失
                        this.$refs.select.visible = true
		},
		// 選擇
		clickItem(item) {
                      const index = this.currentval.indexOf(item.value)
                      if (index == -1) {
                        if (item.value == 'all') {
                          this.currentval = ['all']
                          this.selectItem = [{
                            label: '全部',
                            value: 'all'
                          }]
                        } else {
                          this.currentval.push(item.value)
                          this.selectItem.push(item)
                          const currentvalIndex = this.currentval.indexOf('all')
                          const selectItemIndex = this.selectItem.findIndex(n => n.value == 'all')
                          if (currentvalIndex != -1 && selectItemIndex != -1) {
                            this.selectItem.splice(selectItemIndex, 1)
                            this.currentval.splice(currentvalIndex, 1)
                          }
                        }
                      } else {
                        const itemIndex = this.selectItem.findIndex(n => n.value == item.value)
                        this.selectItem.splice(itemIndex, 1)
                        this.currentval.splice(index, 1)
                      }
                    },
		// 搜索
		seachBtn() {
                        this.getList()
		}
	}
	}

css:

selected屬性使用了el-select的樣式,讓樣子盡量一致

.arrbox {
display: inline-block;
}
.check-select{
::v-deep.hide-popper{
	display: none;
}
}
::v-deep .el-input__suffix{
i:not(.el-select__caret){
	display: none;
}
}
.selectMain {
width: 100%;
height: 100%;
.seachButton{
	width: 100%;
	align-items: center;
	display: flex;
	div.btn{
	width: 25%;
	max-width: 70px;
	max-width: 80px;
	height: 40px;
	display: flex;
	align-items: center;
	justify-content: center;
	font-size: 12px;
	color: #fff;
	background-color: #409EFF;
	border-radius: 5px;
	cursor: pointer;
	}
}
.selectDiv{
        width: 100%;
        max-width: 500px;
        margin-top: 10px;
        padding:  0 10px 0 0;
        .list{
          width: 100%;
          padding: 10px 20px 10px 10px;
          color: #666;
          cursor: pointer;
          position: relative;
          &.selected{
            color: #409EFF;
            &::after{
              position: absolute;
              right: 0px;
              top: 50%;
              transform: translateY(-50%);
              font-family: element-icons;
              content: "\e6da";
              font-size: 12px;
              font-weight: 700;
              -webkit-font-smoothing: antialiased;
            }
          }
        }
        .selectDivAuto{
          width: calc(100% + 15px);
          max-height: 300px;
          overflow-y: auto;
          .list{
            padding: 10px 30px 10px 10px;
            &.selected::after{
              right: 10px;
            }
          }
        }

      }
}
.allCheck{
border-bottom: 1px solid rgb(228, 225, 225);
}

使用

<template>
	<seachSelectInput v-model="from.tag" :parentSelectItem='selectItem' :width="302" placeholder="請(qǐng)選擇標(biāo)簽" />
</template>
<script>
import seachSelectInput from ./seachSelectInput'
export default {
components: {
	seachSelectInput
},
data(){
	return{
		from:{
			tag:['1']
		},
		selectItem:[
			{
			value: '1',
			label: '測(cè)試1'
			}
		]
	}
}
}

總結(jié)

到此這篇關(guān)于ElementUI實(shí)現(xiàn)在下拉列表里面進(jìn)行搜索功能的文章就介紹到這了,更多相關(guān)ElementUI下拉列表搜索內(nèi)容請(qǐng)搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!

相關(guān)文章

  • Vue實(shí)現(xiàn)英文字母大小寫(xiě)在線轉(zhuǎn)換功能

    Vue實(shí)現(xiàn)英文字母大小寫(xiě)在線轉(zhuǎn)換功能

    在Web開(kāi)發(fā)中,字符串處理是常見(jiàn)的需求之一,特別是在國(guó)際化應(yīng)用中,對(duì)于文本的格式化處理尤為重要,本文將介紹如何使用Vue.js來(lái)構(gòu)建一個(gè)簡(jiǎn)單的在線英文字母大小寫(xiě)轉(zhuǎn)換工具,需要的朋友可以參考下
    2024-09-09
  • vue項(xiàng)目引入ts步驟(小結(jié))

    vue項(xiàng)目引入ts步驟(小結(jié))

    這篇文章主要介紹了vue項(xiàng)目引入ts步驟(小結(jié)),文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來(lái)一起學(xué)習(xí)學(xué)習(xí)吧
    2019-10-10
  • Vue中filter使用及根據(jù)id刪除數(shù)組元素方式

    Vue中filter使用及根據(jù)id刪除數(shù)組元素方式

    這篇文章主要介紹了Vue中filter使用及根據(jù)id刪除數(shù)組元素方式,具有很好的參考價(jià)值,希望對(duì)大家有所幫助,如有錯(cuò)誤或未考慮完全的地方,望不吝賜教
    2024-03-03
  • 前端Vue2、Vue3和不同版本nuxt的插槽使用詳解

    前端Vue2、Vue3和不同版本nuxt的插槽使用詳解

    這篇文章主要介紹了前端Vue2、Vue3和不同版本nuxt的插槽使用的相關(guān)資料,Vue2和Vue3中,插槽機(jī)制允許在組件模板中定義占位符,并在使用組件時(shí)插入自定義內(nèi)容,文中通過(guò)代碼介紹的非常詳細(xì),需要的朋友可以參考下
    2025-02-02
  • 關(guān)于Element-UI中slot的用法及說(shuō)明

    關(guān)于Element-UI中slot的用法及說(shuō)明

    這篇文章主要介紹了關(guān)于Element-UI中slot的用法及說(shuō)明,具有很好的參考價(jià)值,希望對(duì)大家有所幫助,如有錯(cuò)誤或未考慮完全的地方,望不吝賜教
    2023-10-10
  • Vue之定義全局工具類(lèi)問(wèn)題

    Vue之定義全局工具類(lèi)問(wèn)題

    這篇文章主要介紹了Vue之定義全局工具類(lèi)問(wèn)題,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。如有錯(cuò)誤或未考慮完全的地方,望不吝賜教
    2023-05-05
  • 如何使用 Vue Router 的 meta 屬性實(shí)現(xiàn)多種功能

    如何使用 Vue Router 的 meta 屬性實(shí)現(xiàn)多種功能

    在Vue.js中,Vue Router 提供了強(qiáng)大的路由管理功能,通過(guò)meta屬性,我們可以在路由定義中添加自定義元數(shù)據(jù),以實(shí)現(xiàn)訪問(wèn)控制、頁(yè)面標(biāo)題設(shè)置、角色權(quán)限管理、頁(yè)面過(guò)渡效果,本文將總結(jié)如何使用 meta 屬性來(lái)實(shí)現(xiàn)這些常見(jiàn)的功能,感興趣的朋友一起看看吧
    2024-06-06
  • Vue開(kāi)發(fā)環(huán)境的搭建全過(guò)程

    Vue開(kāi)發(fā)環(huán)境的搭建全過(guò)程

    文章介紹了在網(wǎng)頁(yè)中使用Vue.js的四種方式:基本方式、腳手架方式(Vue2.0)、使用WebStorm集成環(huán)境創(chuàng)建vue-cli項(xiàng)目(Vue3.0)以及Vue項(xiàng)目的目錄結(jié)構(gòu),每種方式都有詳細(xì)的步驟和示例,幫助讀者快速上手Vue.js開(kāi)發(fā)
    2024-11-11
  • vue中如何實(shí)現(xiàn)拖拽調(diào)整順序功能

    vue中如何實(shí)現(xiàn)拖拽調(diào)整順序功能

    這篇文章主要介紹了vue中如何實(shí)現(xiàn)拖拽調(diào)整順序功能問(wèn)題,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。如有錯(cuò)誤或未考慮完全的地方,望不吝賜教
    2023-05-05
  • Vue中添加手機(jī)驗(yàn)證碼組件功能操作方法

    Vue中添加手機(jī)驗(yàn)證碼組件功能操作方法

    組件是Vue.js最強(qiáng)大的功能之一。組件可以擴(kuò)展HTML元素,封裝可重用的代碼。這篇文章主要介紹了VUE 中添加手機(jī)驗(yàn)證碼組件,需要的朋友可以參考下
    2017-12-12

最新評(píng)論

杭锦旗| 靖宇县| 余姚市| 木里| 洪泽县| 桦南县| 五指山市| 阜南县| 九龙城区| 甘泉县| 天台县| 项城市| 汕尾市| 集安市| 滨海县| 临猗县| 敖汉旗| 鄂托克旗| 界首市| 东辽县| 福贡县| 蚌埠市| 荆州市| 金华市| 江城| 老河口市| 萝北县| 平顶山市| 吉木萨尔县| 九江市| 漳州市| 玛多县| 宣城市| 淮北市| 太原市| 涡阳县| 玛多县| 锦屏县| 苍溪县| 保康县| 吉隆县|