el-table表头添加搜索

案例图:

思路:

添加一个插槽,是用popover组件展示input搜索框,在按下回车键时关闭popover组件且调用查询方法。

部分代码(HTML):

html 复制代码
<template #header >
       {{item.label}}
      <el-popover :visible="item.visible" placement="top" :width="160"  :ref="`popover-${index}`" v-if="item.label=='操作类型'">
         <el-input v-model="input"  placeholder="请输入搜索条件"   @keydown.enter="changeData($event,index)"/>
         <template #reference>
           <el-button  circle class="buttonIcon"><el-icon @click="Ones(item,index)"><Search /></el-icon></el-button>
         </template>
       </el-popover>  
      </template>

JavaScript:

javascript 复制代码
 Ones (val,index) {
      console.log(val, "val",index)
      this.tableHeader[index].visible=!this.tableHeader[index].visible
    },
   
    /**
     * 回车事件
     */
     changeData(event,index) {
       if (!event.ctrlKey) {
         // 如果没有按下组合键ctrl,则会阻止默认事件
         event.preventDefault();
         this.test(index);
       } else {
         // 如果同时按下ctrl+回车键,则会换行
         this.orderInfo += '\n';
       }
     },
     // 测试事件
     test(index){
       console.log('触发了回车事件,并且没有换行喔~');
       this.tableHeader[index].visible=!this.tableHeader[index].visible
      //  下面可以写方法。。。
     },
相关推荐
默_笙12 小时前
🚦 请三个 AI 考官给 RAG 打分:量化评估实战(下)
前端·javascript
阿坨12 小时前
灵感闪存卡:一款 Tampermonkey用户脚本
javascript·tampermonkey
朝朝辞暮i14 小时前
C++ 第 25 课:getter / setter + this
java·javascript·c++
蜗牛互联网14 小时前
Python接入Gemini 3.8 Flash实现票据视觉抽取与规则校验
java·javascript·网络·人工智能·python
易朵朵15 小时前
CSS 格式化上下文
css·vue.js
xieter15 小时前
【技术精选】深入浅出现代前端渲染与性能优化实践指南 (2026-10-04)
前端·javascript
xieter15 小时前
【硬核实战】TypeScript Compiler API: Preserving Child Node Narrowing in Reusable Type Guards 🔧 (2026-10-03)
前端·javascript
xieter15 小时前
【硬核实战】React 19 useFormStatus Returning False? I Built a SubmitButton That Fixes It (2026-10-03)
前端·javascript
雪芽蓝域zzs16 小时前
第6节:远程搜索弹窗(remote 模式),弹窗滚动加载分页
vue.js·elementui
paopaokaka_luck17 小时前
非遗文物数字化小程序(AI非遗问答、ONNX图像识别、协同过滤推荐、ECharts数据分析、非遗知识浏览与互动、文创商城订单闭环、文化活动报名签到、社区交流)
javascript·spring boot·mysql·数据分析·echarts·mybatis