element(vue2)表格插槽

#default="{row}"形式

#:是v-solt的缩写

default:是内容的意思

也可以用

#default="scope"

scope.row.属性

这里的scope里边有很多属性可以获取rowIndex,只是获取内容可以{row}

原文链接:https://blog.csdn.net/weixin_53641562/article/details/124066501

方法1

复制代码
<el-table :data="records_data" height="250" border style="width: 100%" :header-cell-style="tableHeaderColor">
        //多层级表头
      <el-table-column label="进出记录" align="center">
        <el-table-column type="index" width="180" label="序号"> </el-table-column>
        <el-table-column prop="intime" label="时间"> </el-table-column>
        //插槽
        <el-table-column prop="type" label="状态" width="180">
          <template #default="{ row }"> {{ row.type == 0 ? '入场' : '离场' }} </template>
        </el-table-column>
      </el-table-column>
    </el-table>




//js
    //根据不同条件设置表头样式
    tableHeaderColor({ row, column, rowIndex, columnIndex }) {
      console.log(row, column, rowIndex, columnIndex)
      if (rowIndex === 0) {
        return 'background-color: #F5F7FA; color:#3E3F41;'
      } else {
        return 'color:#3E3F41; background: #ffffff;'
      }
    },

方法2

复制代码
<el-table :data="records_data" height="250" border style="width: 100%" :header-cell-style="tableHeaderColor">
      <el-table-column label="进出记录" align="center">
        <el-table-column type="index" width="180" label="序号"> </el-table-column>
        <el-table-column prop="intime" label="时间"> </el-table-column>
        <el-table-column prop="type" label="状态" width="180">
            <template slot-scope="scope">
              {{ scope.row.type == 0 ? '入场' : '离场' }}
            </template>
        </el-table-column>
      </el-table-column>
    </el-table>


//js
    tableHeaderColor({ row, column, rowIndex, columnIndex }) {
      console.log(row, column, rowIndex, columnIndex)
      if (rowIndex === 0) {
        return 'background-color: #F5F7FA; color:#3E3F41;'
      } else {
        return 'color:#3E3F41; background: #ffffff;'
      }
    },
相关推荐
炫饭第一名5 小时前
速通Canvas指北🦮——基础入门篇
前端·javascript·程序员
Forever7_6 小时前
Electron 淘汰!新的桌面端框架 更强大、更轻量化
前端·vue.js
不会敲代码16 小时前
前端组件化样式隔离实战:React CSS Modules、styled-components 与 Vue scoped 对比
css·vue.js·react.js
Angelial6 小时前
Vue3 嵌套路由 KeepAlive:动态缓存与反向配置方案
前端·vue.js
进击的尘埃7 小时前
Vue3 响应式原理:从 Proxy 到依赖收集,手撸一个迷你 reactivity
javascript
willow7 小时前
JavaScript数据类型整理1
javascript
LeeYaMaster7 小时前
20个例子掌握RxJS——第十一章实现 WebSocket 消息节流
javascript·angular.js
UIUV8 小时前
RAG技术学习笔记(含实操解析)
javascript·langchain·llm
SuperEugene8 小时前
Vue状态管理扫盲篇:如何设计一个合理的全局状态树 | 用户、权限、字典、布局配置
前端·vue.js·面试
阿懂在掘金8 小时前
defineModel 是进步还是边界陷阱?双数据源组件的选择逻辑
vue.js·源码阅读