el-table表头添加搜索

案例图:

思路:

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

部分代码(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:

 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
      //  下面可以写方法。。。
     },

 

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值