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
      //  下面可以写方法。。。
     },
相关推荐
武清伯MVP15 小时前
前端跨域方案大合集
前端·javascript
一杯奶茶¥15 小时前
基于springboot的失物招领管理系统带万字文档 校园失物招领管理系统 失物认领管理系统java springboot vue
java·vue.js·spring boot·java项目
星星在线16 小时前
我是怎么把页面图片流量砍掉一半的
前端·javascript
kyriewen17 小时前
TypeScript 高级类型:我用 infer 写了一个类型安全的 EventBus,终于搞懂了泛型约束
前端·javascript·typescript
林希_Rachel_傻希希19 小时前
1小时速通React之Hooks
前端·javascript·面试
石山代码19 小时前
JavaScript 进阶核心知识点
开发语言·javascript·ecmascript
OpenTiny社区20 小时前
这次更新太良心!GenUI SDK v1.2.0 轻量化 + 稳流式 + 超强 Playground
前端·vue.js·ai编程
m0_5474866620 小时前
《HTML+CSS+JavaScript+Vue前端开发技术教程》全套PPT课件
javascript·css·html
FliPPeDround21 小时前
告别离线 Agent:deepseek-kit 内置 Web Search,零配置联网搜索
javascript·agent·deepseek
米丘21 小时前
SSE (server-sent events)
javascript·网络协议