iis服务器助手广告广告
返回顶部
首页 > 资讯 > 精选 >ElementUI怎么实现在下拉列表里面进行搜索功能
  • 464
分享到

ElementUI怎么实现在下拉列表里面进行搜索功能

2023-07-05 20:07:54 464人浏览 八月长安
摘要

这篇文章主要讲解了“ElementUI怎么实现在下拉列表里面进行搜索功能”,文中的讲解内容简单清晰,易于学习与理解,下面请大家跟着小编的思路慢慢深入,一起来研究和学习“ElementUI怎么实现在下拉列表里面进行搜索功能”吧!分析:首先我们

这篇文章主要讲解了“ElementUI怎么实现在下拉列表里面进行搜索功能”,文中的讲解内容简单清晰,易于学习与理解,下面请大家跟着小编的思路慢慢深入,一起来研究和学习“ElementUI怎么实现在下拉列表里面进行搜索功能”吧!

分析:

ElementUI怎么实现在下拉列表里面进行搜索功能

  1. 首先我们需要实现上图的效果,然后Element-UI的el-select是没有的,所以需要自己写

  2. 我们需要用到el-popover组件,然后使用它的v-model="visible"来实现控制显示

  3. 我们在el-popover的slot="reference" 放一个el-select

    1. 使用popper-append-to-body="false"不需要插入浮动元素

    2. 使用popper-class="hide-popper"定义浮窗class为hide-popper,并设置display:none,这样选中了就不会存在el-select的下拉选项

    3. el-option 循环下面选择的list里面的元素,这样就可以在el-select展示选中的并存在删除

    4. el-select双向绑定的就是自定义选择的数组

html:

<template><div class="arrbox"><!-- 通过visible控制显示还是隐藏 --><el-popoverv-model="visible"placement="bottom-start"width="auto"><div slot="reference" class="check-select"><!-- popper-append-to-body:不需要插入浮动元素,popper-class:设置类名并隐藏 --><el-selectref="select"v-model="currentval":multiple:placeholder="placeholder":popper-append-to-body="false"popper-class="hide-popper"@visible-change="visibleChange"@focus="getFocus"> <el-optionv-for="item in selectItem":key="`${item.value}_k`":label="item.label":value="item.value"/></el-select></div><!-- selectBxClick让select强制选中 --><div class="selectMain" : @click="selectBxClick"><div class="seachButton"><el-selectv-model="seachValue"placeholder=" 请选择筛选"@visible-change="selectBxClick()"><el-optionv-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,这样就可以显示出自定义的下拉选择项

通过visibleChange实施监听el-select,控制el-popover显示

在点击自定义的下拉选择项时,通过@click="selectBxClick"el-select一直聚焦,这样箭头就会一直向上

通过 @click="seachBtn"getList获取列表,具体需要自己去自定义

// 模拟获取的数据const seachClickList = [{value: '1',label: '测试1',type: '1'},{value: '2',label: '测试2',type: '1'},{value: '3',label: '测试3',type: '1'},{value: '4',label: '测试4',type: '2'},{value: '5',label: '测试5',type: '2'},{value: '6',label: '测试6',type: '2'},{value: '7',label: '测试7',type: '2'}]export default {model: {prop: 'parentArr',event: 'change-parentArr'},props: {parentArr: {type: Array,default() {return []}},// 传入选中的item,主要时防止list里面没有选中的数据parentSelectItem: {type: Array,default() {return []}},width: {type: Number,default: 300},height: {type: Number,default: 30},placeholder: {type: String,default: '请输入'}},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()},// 获取选中的itemgetSelectItem() {                        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() {                        // 避免点击框体时组件消失                        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="请选择标签" /></template><script>import seachSelectInput from ./seachSelectInput'export default {components: {seachSelectInput},data(){return{from:{tag:['1']},selectItem:[{value: '1',label: '测试1'}]}}}

感谢各位的阅读,以上就是“ElementUI怎么实现在下拉列表里面进行搜索功能”的内容了,经过本文的学习后,相信大家对ElementUI怎么实现在下拉列表里面进行搜索功能这一问题有了更深刻的体会,具体使用情况还需要大家实践验证。这里是编程网,小编将为大家推送更多相关知识点的文章,欢迎关注!

--结束END--

本文标题: ElementUI怎么实现在下拉列表里面进行搜索功能

本文链接: https://www.lsjlt.com/news/354944.html(转载时请注明来源链接)

有问题或投稿请发送至: 邮箱/279061341@qq.com    QQ/279061341

本篇文章演示代码以及资料文档资料下载

下载Word文档到电脑,方便收藏和打印~

下载Word文档
猜你喜欢
  • ElementUI怎么实现在下拉列表里面进行搜索功能
    这篇文章主要讲解了“ElementUI怎么实现在下拉列表里面进行搜索功能”,文中的讲解内容简单清晰,易于学习与理解,下面请大家跟着小编的思路慢慢深入,一起来研究和学习“ElementUI怎么实现在下拉列表里面进行搜索功能”吧!分析:首先我们...
    99+
    2023-07-05
  • ElementUI实现在下拉列表里面进行搜索功能详解
    目录分析:html:js:css:使用总结分析: 首先我们需要实现上图的效果,然后Element-UI的el-select是没有的,所以需要自己写我们需要用到el-pop...
    99+
    2023-05-14
    element的下拉列表 element下拉框带搜索 elementui下拉列表搜索
  • vue+elementui实现下拉表格多选和搜索功能
    本文实例为大家分享了vue+elementui实现下拉表格多选和搜索的具体代码,供大家参考,具体内容如下 在elementui的基础上对下拉框和表格进行组合 template ...
    99+
    2022-11-12
  • vue+elementui如何实现下拉表格多选和搜索功能
    这篇文章主要介绍“vue+elementui如何实现下拉表格多选和搜索功能”,在日常操作中,相信很多人在vue+elementui如何实现下拉表格多选和搜索功能问题上存在疑惑,小编查阅了各式资料,整理出简单好用的操作方法,希望对大家解答”v...
    99+
    2023-06-21
  • jQuery UI如何仿淘宝实现搜索下拉列表功能
    这篇文章主要为大家展示了“jQuery UI如何仿淘宝实现搜索下拉列表功能”,内容简而易懂,条理清晰,希望能够帮助大家解决疑惑,下面让小编带领大家一起研究并学习一下“jQuery UI如何仿淘宝实现搜索下拉...
    99+
    2022-10-19
  • 怎么使用vue实现可搜索下拉框功能
    本篇内容主要讲解“怎么使用vue实现可搜索下拉框功能”,感兴趣的朋友不妨来看看。本文介绍的方法操作简单快捷,实用性强。下面就让小编来带大家学习“怎么使用vue实现可搜索下拉框功能”吧!效果图:子组件 DROPDOWN.VUE<...
    99+
    2023-07-04
  • 利用bootstrap怎么实现一个下拉框搜索功能
    本篇文章为大家展示了利用bootstrap怎么实现一个下拉框搜索功能,内容简明扼要并且容易理解,绝对能使你眼前一亮,通过这篇文章的详细介绍希望你能有所收获。1、第一个下拉框代码<div class="btn-gro...
    99+
    2023-05-31
    bootstrap strap
  • BootStrap怎么实现鼠标悬停下拉列表功能
    这篇文章主要介绍了BootStrap怎么实现鼠标悬停下拉列表功能,具有一定借鉴价值,感兴趣的朋友可以参考下,希望大家阅读完这篇文章之后大有收获,下面让小编带着大家一起了解一下。BootStrap实现鼠标悬停...
    99+
    2022-10-19
  • 怎么使用elementUI组件实现表格的分页及搜索功能
    今天小编给大家分享一下怎么使用elementUI组件实现表格的分页及搜索功能的相关知识点,内容详细,逻辑清晰,相信大部分人都还太了解这方面的知识,所以分享这篇文章给大家参考一下,希望大家阅读完这篇文章后有所收获,下面我们一起来了解一下吧。主...
    99+
    2023-07-05
  • 怎么在Android应用中利用PopuWindow实现一个下拉列表功能
    这篇文章将为大家详细讲解有关怎么在Android应用中利用PopuWindow实现一个下拉列表功能,文章内容质量较高,因此小编分享给大家做个参考,希望大家阅读完这篇文章后对相关知识有一定的了解。基础依赖,由于下拉列表是用RecycleVie...
    99+
    2023-05-31
    popuwindow roi android
  • 怎么用Thinkphp+Ajax实现带关键词搜索列表无刷新分页的功能
    这篇文章主要讲解了“怎么用Thinkphp+Ajax实现带关键词搜索列表无刷新分页的功能”,文中的讲解内容简单清晰,易于学习与理解,下面请大家跟着小编的思路慢慢深入,一起来研究和学习“怎么用Thinkphp+Ajax实现带关键词搜索列表无刷...
    99+
    2023-06-04
软考高级职称资格查询
编程网,编程工程师的家园,是目前国内优秀的开源技术社区之一,形成了由开源软件库、代码分享、资讯、协作翻译、讨论区和博客等几大频道内容,为IT开发者提供了一个发现、使用、并交流开源技术的平台。
  • 官方手机版

  • 微信公众号

  • 商务合作