elementUi中的el-table合计行添加点击事件

elementUi 文档中,合计行并没有点击事件,这里自己实现了合计行的点击事件。

javascript 复制代码
  created() {
    this.propertyList = [
      { property: 'order', label: '序号' },
      { property: 'deptName', label: '单位名称' },
      { property: 'contentPublishQuantity', label: '文章数量' },
      { property: 'readQuantity', label: '浏览量' },
      { property: 'likeQuantity', label: '点赞量' },
      { property: 'collectionQuantity', label: '收藏量' },
    ]
  },
 mounted() {
    let that = this
    setTimeout(() => {
      const footerWrapper = this.$el.querySelector('.el-table__footer-wrapper');
      const cells = this.$el.querySelectorAll('.el-table__footer-wrapper td .cell');
      // 给文章数量和收藏量添加样式
      let clickIndex = [2,5]
      if (cells.length) {
        cells.forEach((cell, index) => {
          if (clickIndex.includes(index)) {
            cell.style.color = '#409EFF'
            cell.style.cursor = 'pointer'
          }
        })
      }
      // 在合计行添加点击事件
      footerWrapper.addEventListener('click', (event) => {
        // 检查点击事件是否发生在合计行的单元格上
        const targetCell = event.target.closest('.el-table__cell');
        if (targetCell) {
          // 获取点击的列索引
          const columnIndex = Array.from(targetCell.parentNode.children).indexOf(targetCell);
          if (columnIndex !== -1) {
            console.log('当前点击项:',that.propertyList[columnIndex])
          }
        }
      });
    }, 500)

  },
相关推荐
大家的林语冰9 小时前
Rust 再次打败 Go,Astro 7 首发,什么叫“万物皆可锈化“!
前端·javascript·性能优化
用户938515635079 小时前
从零打造你的第一个智能体(Agent):*手写一个能自主建项目的Mini Cursor (三)
javascript·人工智能·后端
aichitang20249 小时前
Claude fable 5与GPT5.5模型能力实测
javascript·css·人工智能·ai·html·html5
多加点辣也没关系9 小时前
JavaScript|第6章:流程控制语句
开发语言·前端·javascript
用户938515635079 小时前
手写迷你 Cursor 终端:深入 Node.js child_process 的 spawn 核心实现
javascript·后端
Csvn10 小时前
AbortController 不止能取消 Fetch!3 个你不知道的隐藏用法
前端·javascript
大流星10 小时前
LangChainJS之Runnable(三)
javascript·langchain
张元清10 小时前
React useLocalStorage Hook:SSR 安全的持久化状态(2026)
javascript·react.js
甜味弥漫10 小时前
React Router:从单页应用到前端路由
javascript·node.js
lkshop10 小时前
Next.js 网站 SEO 优化:从 SSR、Sitemap 到结构化数据
开发语言·javascript·ecmascript