一个根据输入内容过滤下拉选的组件

server/2025/2/22 22:14:18/

1.element的select自定义过滤不是很灵,使用了input和dropdown

组件

<template><div class="autocomplete-wrapper"><!-- 使用 el-input 组件 --><el-inputv-model="inputValue"@input="handleInput"placeholder="请输入内容"/><!-- 使用 el-dropdown 自定义下拉框 --><el-dropdownref="dropdown1"trigger="manual"placement="bottom-start"popper-class="autocomplete-dropdown"><div class="menu_title">55555</div><!-- 空 div 作为触发元素 --><template #dropdown><ul class="suggestions"><liv-for="item in filteredOptions":key="item[valueStr]"@click="selectOption(item[valueStr])">{{ item[valueStr] }}</li></ul></template></el-dropdown></div>
</template><script setup>
import { ref, computed, onMounted } from "vue";
const { proxy } = getCurrentInstance();
defineProps({
//接口参数options: {type: Array,default: true,},
//input关联的变量inputValue:{type: String,default: "",  },
//接口地址oprionUrl: {type: String,default: "",},
//option需要展示的属性名valueStr:{type:String,default:"name"}
});
// const inputValue = ref("")
const emit = defineEmits(["setInput"]);
getDeviceCodeList();
let allDeviceCodeList = [];
function getDeviceCodeList() {}// 过滤后的选项
const filteredOptions = ref([]);// 输入处理function handleInput (input)  {proxy.$get(proxy.oprionUrl,).then((res) => {allDeviceCodeList = res.records;filteredOptions.value = []let arr = input.split("");let regx = "";arr.forEach((element) => {regx += `(${element})(.)*`;});let regxN = new RegExp(regx);allDeviceCodeList.forEach((item) => {if (regxN.test(item[proxy.valueStr])) {filteredOptions.value.push(item);}});if(filteredOptions.value.length>0){openDropdown()}});
};// 选择选项
const selectOption = (value) => {closeDropdown()emit("setInput", value);
};// 关闭下拉框
const closeDropdown = () => {proxy.$refs.dropdown1.handleClose();
};// 打开下拉框
const openDropdown = () => {proxy.$refs.dropdown1.handleOpen();
};
</script><style scoped>
.autocomplete-wrapper {position: relative;width: 120px;
}
.menu_title{position: absolute;top:20px;left: -120px;opacity: 0;
}
.suggestions {width: 300px;max-height: 200px;overflow-y: auto;margin: 0;padding: 0;border: 0px solid #292626;border-radius: 4px;background: rgb(8, 42, 84);color: #ffffff;list-style: none;
}.suggestions li {padding: 8px;cursor: pointer;
}.suggestions li:hover,
.highlighted {background-color: rgb(3, 85, 159);
}mark {background-color: yellow;padding: 0;
}
</style>

父组件使用

handleSelect赋值

<template><SI:options="queryParams":oprionUrl="url":inputValue="queryParams.input"valueStr="optionValue"@setInput="handleSelect"/>
</template>
<script setup>
import SI from "./SI.vue"
function handleSelect(params) {proxy.queryParams.deviceCode = params
}</script>


http://www.ppmy.cn/server/169177.html

相关文章

React生产环境下使用mock.js

最近项目中有个需求,甲方要求在生产环境中使用mock.js数据展示前端项目&#xff0c;因为后端接口暂时没有。我的项目是通过vite构建的&#xff0c;前端项目在打包后一般不会将mock代码数据打包到dist文件夹中进而也不会调用mock数据&#xff0c;所以导致前端项目部署到nginx上后…

Rook-ceph(1.92最新版)

安装前准备 #确认安装lvm2 yum install lvm2 -y #启用rbd模块 modprobe rbd cat > /etc/rc.sysinit << EOF #!/bin/bash for file in /etc/sysconfig/modules/*.modules do[ -x \$file ] && \$file done EOF cat > /etc/sysconfig/modules/rbd.modules &l…

【Spring详解一】Spring整体架构和环境搭建

一、Spring整体架构和环境搭建 1.1 Spring的整体架构 Spring框架是一个分层架构&#xff0c;包含一系列功能要素&#xff0c;被分为大约20个模块 Spring核心容器&#xff1a;包含Core、Bean、Context、Expression Language模块 Core &#xff1a;其他组件的基本核心&#xff…

【设计模式】 代理模式(静态代理、动态代理{JDK动态代理、JDK动态代理与CGLIB动态代理的区别})

代理模式 代理模式是一种结构型设计模式&#xff0c;它提供了一种替代访问的方法&#xff0c;即通过代理对象来间接访问目标对象。代理模式可以在不改变原始类代码的情况下&#xff0c;增加额外的功能&#xff0c;如权限控制、日志记录等。 静态代理 静态代理是指创建的或特…

Office hour 2-自然语言处理

主要涉及**自然语言处理&#xff08;NLP&#xff09;**的多个方面&#xff0c;包括发展历程、神经网络模型、大语言模型、以及实际应用。 01 - NLP的发展历程 1. 1950 - 1969&#xff1a; • 机器翻译研究&#xff1a;NLP的研究始于机器翻译&#xff0c;探索计算机如何处理和…

以用户为中心,汽车 HMI 界面设计的创新之道

在汽车智能化飞速发展的当下&#xff0c;汽车 HMI&#xff08;人机交互界面&#xff09;成为连接人与车的关键桥梁。如何打造出优秀的 HMI 界面&#xff1f;答案是以用户为中心&#xff0c;探索创新之道。 用户需求是汽车 HMI 界面设计的指南针。在设计前期&#xff0c;深入调…

Spring-GPT智谱清言AI项目(附源码)

一、项目介绍 本项目是Spring AI第三方调用整合智谱请言&#xff08;官网是&#xff1a;https://open.bigmodel.cn&#xff09;的案例&#xff0c;回答响应流式输出显示&#xff0c;这里使用的是免费模型&#xff0c;需要其他模型可以去 https://www.bigmodel.cn/pricing 切换…

深入理解Redis

一、引言 在当今高并发、大数据量的互联网应用场景中&#xff0c;提升系统性能和响应速度是后端开发的关键挑战之一。Redis作为一款高性能的内存数据库&#xff0c;以其出色的读写速度、丰富的数据结构和强大的功能特性&#xff0c;成为Java后端开发中不可或缺的缓存和数据存储…