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)

  },
相关推荐
記億揺晃着的那天7 小时前
Vue + Element UI 表格自适应高度如何做?
javascript·vue.js·ui
GISer_Jing8 小时前
ByteDance——jy真题
前端·javascript·面试
真的想不出名儿8 小时前
Vue 中 props 传递数据的坑
前端·javascript·vue.js
阳光阴郁大boy8 小时前
星座运势网站技术解析:从零打造现代化Web应用
前端·javascript
sorryhc8 小时前
如何设计一个架构良好的前端请求库?
前端·javascript·架构
Queen_sy8 小时前
vue3 el-date-picker 日期选择器校验规则-选择日期范围不能超过七天
javascript·vue.js·elementui
lvchaoq9 小时前
react 修复403页面无法在首页跳转问题
前端·javascript·react.js
郝开9 小时前
6. React useState基础使用:useState修改状态的规则;useState修改对象状态的规则
前端·javascript·react.js
技术钱10 小时前
react+andDesign+vite+ts从零搭建后台管理系统(三)-Layout布局
javascript·react.js·ecmascript
DoraBigHead11 小时前
🧭 React 理念:让时间屈服于 UI —— 从同步到可中断的演化之路
前端·javascript·面试