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
      //  下面可以写方法。。。
     },
相关推荐
丫丫7237344 分钟前
Three.js 模型树结构与节点查询学习笔记
javascript·webgl
车传新24 分钟前
Javascript
javascript
天若有情67341 分钟前
【c++】手撸C++ Promise:从零实现通用异步回调组件,支持链式调用+异常安全
开发语言·前端·javascript·c++·promise
抱琴_1 小时前
【Vue3】大屏性能优化黑科技:Vue 3 中实现请求合并,让你的大屏飞起来!
前端·vue.js
hadage2331 小时前
--- JavaScript 的一些常用语法总结 ---
java·前端·javascript
saberxyL2 小时前
通过<RouterView/>来切换页面组件时,transition如何生效?
vue.js
jason_yang2 小时前
vue3中createApp多个实例共享状态
javascript·vue.js
_瑶瑶_2 小时前
浅记一下ElementPlus中的虚拟化表格(el-table-v2)的简单使用
前端·javascript
拉不动的猪2 小时前
Axios 请求取消机制详解
前端·javascript·面试
老华带你飞3 小时前
海产品销售系统|海鲜商城购物|基于SprinBoot+vue的海鲜商城系统(源码+数据库+文档)
java·前端·数据库·vue.js·论文·毕设·海鲜商城购物系统