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;'
      }
    },
相关推荐
H309199 分钟前
vue3+dhtmlx-gantt实现甘特图展示
android·javascript·甘特图
CodeCraft Studio13 分钟前
数据透视表控件DHTMLX Pivot v2.1发布,新增HTML 模板、增强样式等多个功能
前端·javascript·ui·甘特图
llc的足迹24 分钟前
el-menu 折叠后小箭头不会消失
前端·javascript·vue.js
九月TTS1 小时前
TTS-Web-Vue系列:移动端侧边栏与响应式布局深度优化
前端·javascript·vue.js
曾经的你d1 小时前
【electron+vue】常见功能之——调用打开/关闭系统软键盘,解决打包后键盘无法关闭问题
vue.js·electron·计算机外设
积极向上的龙2 小时前
首屏优化,webpack插件用于给html中js自动添加异步加载属性
javascript·webpack·html
Bl_a_ck2 小时前
开发环境(Development Environment)
开发语言·前端·javascript·typescript·ecmascript
田本初2 小时前
使用vite重构vue-cli的vue3项目
前端·vue.js·重构
ai产品老杨3 小时前
AI赋能安全生产,推进数智化转型的智慧油站开源了。
前端·javascript·vue.js·人工智能·ecmascript
帮帮志3 小时前
vue实现与后台springboot传递数据【传值/取值 Axios 】
前端·vue.js·spring boot