位置: IT常识 - 正文

ElementUI实现在下拉列表里面进行搜索(elementui怎么样)

发布时间:2024-01-17
ElementUI实现在下拉列表里面进行搜索 分析:

推荐整理分享ElementUI实现在下拉列表里面进行搜索(elementui怎么样),希望有所帮助,仅作参考,欢迎阅读内容。

文章相关热门搜索词:element-ui,elementui怎么样,element-ui,elementui rule,elementui 3,elementui ts,elementui怎么样,elementui怎么样,内容如对您有帮助,希望把文章链接给更多的朋友!

首先我们需要实现上图的效果,然后Element-UI的el-select是没有的,所以需要自己写我们需要用到el-popover组件,然后使用它的v-model="visible"来实现控制显示我们在el-popover的slot="reference" 放一个el-select使用popper-append-to-body="false"不需要插入浮动元素使用popper-class="hide-popper"定义浮窗class为hide-popper,并设置 display:none,这样选中了就不会存在el-select的下拉选项el-option 循环下面选择的list里面的元素,这样就可以在el-select展示选中的并存在删除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":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-optionv-for="item in selectItem":key="`${item.value}_k`":label="item.label":value="item.value"/></el-select></div><!-- selectBxClick让select强制选中 --><div class="selectMain" :style="{'min-width':`${width-20}px`}" @click="selectBxClick"><div class="seachButton"><el-selectv-model="seachValue"placeholder=" 请选择筛选"style="width:70%;margin-right:10px;max-width:195px"@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:ElementUI实现在下拉列表里面进行搜索(elementui怎么样)

使用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'}]}}}
本文链接地址:https://www.jiuchutong.com/zhishi/299521.html 转载请保留说明!

上一篇:GPU版本安装Pytorch教程最新方法(gpu版本的pytorch)

下一篇:基于chatGPT设计卷积神经网络

  • 税务师报名入口官网2022
  • 其他应付款为负数
  • 上期有留抵进项税额,本期如何转,如何做账
  • 退税发票误勾选怎么撤销
  • 营改增后工程税收怎么计算
  • 销售承兑现金会退回来吗
  • 资产负债率计算方式
  • 股东转入投资款
  • 股东利润分配怎么交税
  • 公司购电缆用于生产如何记账?
  • 材料采购计入什么会计科
  • 有限合伙企业对外转让财产份额
  • 企业注销时留抵税额怎么做账
  • 税控盘抵税可以跨年吗
  • 预缴纳税申报失败怎么办
  • 减半征税怎么算
  • 公司开业期间的费用入管理费用其他行吗
  • 企业新建厂房
  • 营改增后城建税怎么算
  • 其他收益是一级科目还是二级科目
  • 对个体工商户个人的认识
  • 非货币性资产交换差额计入什么科目
  • 生产的废料怎么做账
  • qq游戏怎么玩不了怎么回事
  • bios术语
  • gif图片查看软件
  • 在windows7中,使用鼠标拖放功能
  • 实收资本属于哪类
  • 租赁合同维修义务谁承担
  • 新政府会计制度科目表
  • win7系统中怎样没有智能卡这一选项
  • linux中cut命令详解
  • PHP:spl_object_hash()的用法_spl函数
  • win7无法打开打印机
  • php生成php文件
  • 其他应付款的会计科目
  • PHP:imagepsencodefont()的用法_GD库图像处理函数
  • 外请培训老师的路费谁承担
  • 微前端Qiankun
  • vue中 router.beforeEach() 的用法
  • vgremove命令
  • 社会团体会员费做分录
  • Joe是一款优雅功能强大的Typecho主题功能多上手快
  • 有限合伙企业的执行事务合伙人
  • 织梦系统
  • sql server中变量声明的命令是什么
  • 一般纳税人和小规模纳税人怎么界定
  • 预算收入分为哪几种方式
  • 投资收益的主要形式有
  • 视同销售的几种情况都有什么?
  • 金税四期能监控到公户吗
  • 财政拨入的专项款专账怎么做
  • 汇算清缴 房租
  • 应交税费期末余额在借方怎样处理
  • 自然人系统如何恢复数据
  • 如何理解会计含义
  • 限定性净资产举例
  • innodb.trx
  • win10 rs5
  • 用u盘装系统怎么操作步骤
  • crowd1登录界面
  • 亲测可用抖音低价单赚派费项目
  • ubuntu终端终止正在执行的命令
  • windows打开或关闭功能
  • xp系统怎么和win7系统共享
  • windows7脚本编程和命令行指南
  • windows语音识别
  • Win10装不上是什么原因
  • linux如何kill进程
  • 安装centos no such device
  • python计算两个数的最大公约数
  • nginx日志切割原理
  • nodejs inspect
  • python快速排序法
  • 键盘事件有三个 分别是
  • javascript教程完整版
  • 湖南历年社保缴费
  • 演艺明星
  • 拟录用和录用的区别在哪
  • 非房地产企业转让旧房土地增值税
  • 免责声明:网站部分图片文字素材来源于网络,如有侵权,请及时告知,我们会第一时间删除,谢谢! 邮箱:opceo@qq.com

    鄂ICP备2023003026号