vue el-input 输入框下拉显示匹配数据
创始人
2024-11-15 13:11:58
1、效果图:

2、需求&实现:

输入条件 下面匹配查询到的数据有多少个 需要调用后端接口展示,后端查询到之后返回条数 前端展示

3、具体代码实现:

html: 图片需要自己根据实际情况增加  // 查询 重置 筛选  本文章只写查询 重置和更多筛选逻辑自行添加

{{item.queryType}}:0,spanNoData:Number(item.number)==0}">{{item.number}}

js代码逻辑

//接口需要自己引入 import { selectNum } from "@/api/xxxx" export default {     data() {       return {        searchFilterFlag: false,        visible: false,         //初始的一些查询条件        searchData: {         queryData: "",         orderByKeyWord: "",         ascOrDesc: "",         orderByRule: "",       },        queryDataLabel: "",        queryList: [         {           queryType: `查询条件1`,           queryParam: "workNo",           number: 0,         },         {           queryType: `查询条件2`,           queryParam: "personName",           number: 0,         },         {           queryType: `查询条件3`,           queryParam: "pmpName",           number: 0,         },         {           queryType: `查询条件4`,           queryParam: "phone",           number: 0,         },         {           queryType: `查询条件5`,           queryParam: "graduationInstitution",           number: 0,         },         {           queryType: `查询条件6`,           queryParam: "insurancesPlace",           number: 0,         },       ],       timer: null,       queryParam: "",       }     },     mounted() {         //增加一个全局监听 方便点击其他位置可以关闭el-popover         document.addEventListener('click', this.handleDocumentClick);     },     methods: {     //点击查询条件的每一条数据      linkageDivClick(item) {       this.visible = false;         // 我们需要把这个值给后端传过去       this.queryParam = item.queryParam;         // 原本的查询条件中 searchData 所有值需要置空       for (let key in this.searchData) {           this.searchData[key] = ""       }       this.searchData[item.queryParam] = this.queryDataLabel;         //去调用查询接口        this.getGridDataEvt('search', false)     },     openPopover() {       this.visible = true;       this.debouncedInput(this.queryDataLabel)     },     // 下拉框查询接口     debouncedInputApi(val) {       selectNum({ queryData: val }).then(res => {         if (res.code == 200) {           let data = res.data           this.queryList.forEach(item => {             for (let key in data) {               if (item.queryParam == key) {                 item.number = data[key]               }             }           })         } else {           this.$message.error('数据获取失败');         }       }).catch(err => {         this.$message.error(err.msg);       })     },     // 输入框触发     debouncedInput(val) {       clearTimeout(this.timer);       //   防抖       this.timer = setTimeout(() => {         this.debouncedInputApi(val)       }, 500);     },     },     beforeDestroy() {         //清除定时       clearTimeout(this.timer);         // 移除监听       document.removeEventListener('click', this.handleDocumentClick);     },  }

样式style  具体效果还是需要自己微调 

.topSearch {         height: 80px;         width: calc(100% - 20px);         display: flex;         align-items: center;         justify-content: center;         .top-search-group {           height: 40px;           width: 750px;           display: flex;           align-items: center;           span {             width: 100%;           }           ::v-deep .el-input__inner {             height: 40px;             border-radius: 4px 0 0 4px;           }           ::v-deep .el-input-group__append {             background: #0096f1;             color: #fff;           }           .searchBtn {             cursor: pointer;             background: #008ee4;             display: flex;             align-items: center;             justify-content: center;             border-radius: 0 4px 4px 0;           }           .iconBtn {             margin-left: 10px;             width: 42px;             height: 40px;             cursor: pointer;             background: #ffffff;             border-radius: 4px;             border: 1px solid #dcdfe6;             display: flex;             align-items: center;             justify-content: center;           }           .iconBtnShaixuan {             margin-left: 10px;             width: 42px;             height: 40px;             cursor: pointer;             background: #ffffff;             border-radius: 4px;             border: 1px solid #dcdfe6;             background: url("../../assets/images/shaixuan.png");             background-repeat: no-repeat;             background-position: center center;             &:hover {               background: url("../../assets/images/shaixuanClick.png");               background-repeat: no-repeat;               background-position: center center;             }           }           .active {             background: #ebf7ff;             border-radius: 4px;             border: 1px solid #cbebff;             display: flex;             align-items: center;             justify-content: center;             &:hover {               background: #ebf7ff;             }           }         }       }

 

相关内容

热门资讯

裸辞做“一人公司”,我后悔了 去年这个时候,一位以色列程序员正在东南亚旅行。他顺手把一个在脑子里转了很久的想法做成了产品,一个让任...
南京建成国内首个Pre-6G试... 4月21日,2026全球6G技术与产业生态大会在南京开幕。全息互动技术展台前,一名远在北京的工作人员...
超梵求职受邀参加“2025抖音... 超梵求职受邀参加“2025抖音巨量引擎成人教育行业生态大会”,探讨分享优质内容传播,服务万千学员。 ...
摩托罗拉Razr 2026(R... IT之家 4 月 22 日消息,摩托罗拉宣布新一代 Razr 折叠手机将于 4 月 29 日在美国发...
库克卸任,特纳斯领航:苹果新纪... 苹果首席执行官蒂姆·库克将卸任,硬件工程主管约翰·特纳斯将接任,苹果公司今天宣布此事。 库克将在夏季...