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
      //  下面可以写方法。。。
     },
相关推荐
kyriewen3 小时前
别再这样写TypeScript了——Code Review中最常见的8个反模式
前端·javascript·typescript
名字还没想好☜3 小时前
Next.js ‘use client‘ 到底加在哪:Server/Client Components 边界与常见报错
开发语言·前端·javascript·react·next.js
飘尘5 小时前
一文讲清楚前端面试会问到的所有缓存
前端·javascript·面试
ThsPool5 小时前
【ENVI二次开发学习整理 04】ENVI功能扩展与二次开发
java·前端·javascript
张元清7 小时前
React useDisclosure Hook:管理模态框和抽屉的打开关闭状态 (2026)
javascript·react.js
天天码行空7 小时前
vkeyboardhand:零依赖虚拟键盘指法组件
前端·javascript·vue.js
我要两颗404西柚8 小时前
Stage four:VUE项目上线
前端·javascript·vue.js
蜡台10 小时前
Flutter Container 与装饰完整讲解
android·javascript·flutter·dart
满栀58510 小时前
原生JS + ECharts 多图表可视化实战:从业务实现到工程化优化
开发语言·javascript·echarts
TinssonTai10 小时前
Vite 8 版 Chrome 插件全家桶,popup/options/sidepanel 一次集齐
前端·vue.js