el-select实现可复制一段“关键词“(多个)实现搜索 以及 回车选中搜索项

el-select实现可复制一段"关键词"(多个)实现搜索 以及 回车选中搜索项

html 复制代码
<el-select
	ref="productRef"
	filterable
	clearable
	v-model="fItem.productName"
	multiple
	:reserve-keyword="true"
	remote
	:filter-method="remoteMethod"
	@visible-change="visibleChange"
	@keyup.enter="handleEnterKey(fIndex)"
>
	<el-option
		v-for="(item3, index3) in portFullNameOpt"
		:key="index3"
		:label="(item3.productCode ? '(' + item3.productCode + ')' : '') + item3.productName"
		:value="item3.productId"
	></el-option>
</el-select>

添加remote属性,用filter-method实现自定义搜索方法

puppet 复制代码
// 多搜索
function remoteMethod(query: any) {
	if (query !== '') {
	// 当前场景query是以空格分开的关键词,比如"001  002",所以处理成数组形式
		state.keyUpData = query.split(' ');
		// 接口过滤
		selectAllProductInfo({ productName: query }).then((res: any) => {
			state.portFullNameOpt = res.data;
		});
	} else {
		state.portFullNameOpt = state.pordOriginalOpt;
	}
}
// 下拉框消失时,恢复默认选项
function visibleChange(data: any) {
	if (!data) {
		state.portFullNameOpt = state.pordOriginalOpt;
	}
}
// 回车自动选中搜索过滤出来的选项
function handleEnterKey(fIndex: number) {
	if (state.keyUpData.length) {
	// 场景:复制搜索的是关键词,但是绑定的是productId,所以处理一下
		const queryProductId = state.portFullNameOpt.filter((item1: { productCode: any }) => state.keyUpData.includes(item1.productCode)).map((item2: { productId: any }) => item2.productId);
		// console.log(queryProductId, 'att');
		state.newAgencySalesList.forEach((item: any, index: number) => {
			if (fIndex == index) {
				item.productName = queryProductId;
			}
		});
	}
}
相关推荐
打妖妖灵滴哪吒28 分钟前
IOS模态窗口的作用与设计原则
前端·ui
午安~婉36 分钟前
挑战二:博客预览卡片
前端·javascript·html
环境栈笔记1 小时前
指纹浏览器安全评测方法:核对环境、数据与权限后再选型
前端·人工智能·后端·自动化
打妖妖灵滴哪吒1 小时前
前端开发/UI设计师-APP中如何进行可发现性设计
前端·ui
Kinghiee1 小时前
从使用场景切入前端常见设计模式
前端·设计模式
郭老二11 小时前
【前端】vue3:编译步骤
前端
不在逃避q11 小时前
Trae/Vs Code/Cursor命令行无法跑npm命令
前端·arcgis·npm
夏殇之殁12 小时前
包中创建自定义列表项。 . 使用自定义列表项进行数据绑定 . 将天气预报数据保存到本地内存表,通过LiveBindings进行显示。 ...
服务器·前端·javascript
The Chosen One98512 小时前
高进度算法模板速记(待完善)
java·前端·算法
陈随易12 小时前
MoonBit抓包模块pcap,查看电脑的每一次联网通信
前端·后端·程序员