记录element-ui改造select显示为table,并支持多查询条件

最近遇到的一个需求 , 很有趣,是需要一个select组件,要求显示工号,员工姓名,以及区域

三个字段,并且要支持三个字段的查询。显然element原生的组件不适用,这时候我们需要改造一下,把option改成一个table的样子,这样就能解决我们的问题 , 多个搜索条件这里我是一次性拿到所有的数据,然后模糊查询来解决

1.先看效果图 点击select支持输入,选择,以及回车查询

2.实现代码 HTML

html 复制代码
 <el-select v-model="value" clearable filterable :filter-method='filterMethod' placeholder="请选择">
   <el-option disabled value="disabled ">
		<div class='saler-mate-list-item disabled-title'>
			<span class='code'>工号</span>
			<span class='name'>姓名</span>
			<span class='spec'>区域</span>
		</div>
	</el-option>

	<template v-if="options && options.length">
	    <el-option
	      v-for="item in options"
	      :key="item.value"
	      :label="item.label"
	      :value="item.value">
			<div class='saler-mate-list-item disabled-title'>
				<span class='code'>{{item.code}}</span>
				<span class='name'>{{item.label}}</span>
				<span class='spec'>{{item.spec}}</span>
			</div>
		</el-option>
	</template>
	<el-option v-else disabled>暂无数据</el-option>
  </el-select>

3. 对应Css

css 复制代码
.saler-mate-list-item{
	display: flex;
 	justify-content: space-between;
	align-items:center;
	width:500px;
	padding-left:20px;
}

.name {
	width:45%;
	text-align:left;
	wite-space:nowrap;
	text-overflow:elipsis;
}

.code{
	width:30%;
	text-align:left;
	wite-space:nowrap;
	text-overflow:elipsis;
}

.spec {
	width:25%;
	text-align:left;
	wite-space:nowrap;
	text-overflow:elipsis;
}

4.对应JS

javascript 复制代码
filterMethod(val){
	if(val){
		// 不建议操作原数组
		let newArr = this.options.filter(i => {
		return i.codo.includes(val) || i.name.includes(val) || i.spec.includes(val)})
		this.options = JSON.parse(JSON.stringify(newArr))
	} else {
		// 搜索内容为空时 , 要把原始数据赛回select中
		this.options = this.dataList
	}
}
相关推荐
代码游侠3 分钟前
学习笔记——ARM Cortex-A 裸机开发实战指南
linux·运维·开发语言·前端·arm开发·笔记
m0_748254666 分钟前
CSS 编辑器
前端·css·编辑器
Amumu121389 分钟前
React扩展(二)
前端·javascript·react.js
rqtz13 分钟前
网页响应式布局方法
前端·css·响应式
郝学胜-神的一滴14 分钟前
Qt与Web混合编程:CEF与QCefView深度解析
开发语言·前端·javascript·c++·qt·程序人生·软件构建
m0_5027249517 分钟前
Arco Design Vue 中的a-upload
前端·javascript·arco design vue
967717 分钟前
最简单版web server
前端
VT.馒头20 分钟前
【力扣】2637. 有时间限制的 Promise 对象
前端·javascript·leetcode·typescript
zhengxianyi51521 分钟前
Vue2 打包部署后通过修改配置文件修改全局变量——实时生效
前端·vue.js·前后端分离·数据大屏·ruoyi-vue-pro
灵犀坠22 分钟前
Vue3 实现音乐播放器歌词功能:解析、匹配、滚动一站式教程
开发语言·前端·javascript·vue.js