el-table根据data动态生成列和行

css

csharp 复制代码
//el-table-column加上fixed后会导致悬浮样式丢失,用下面方法可以避免
.el-table__body .el-table__row.hover-row td{
  background-color: #083a78 !important;
}
.el-table tbody tr:hover>td {
 	background: #171F34 !important;
}

html

csharp 复制代码
   <el-table ref="multipleTable" :data="gridData" :span-method="cellMerge"
                style="min-width: 1300px; white-space: nowrap" header-cell-class-name="headerCellClassName"
                row-class-name="rowClassName" cell-class-name="cellClassName">
                <!--
                 show-summary 
                :summary-method="getSummaries" -->
                <!-- <el-table-column type="index" label="序号"> </el-table-column> -->
                <el-table-column prop="projectName" label="项目" fixed="left"> </el-table-column>
                <el-table-column prop="areaName" label="区域" fixed="left"> </el-table-column>
                <el-table-column
                 v-for="(item,index) in gridData[0].dayList" ley="index">
          <template slot="header" slot-scope="scope">
          {{ item.dayName   }}
          </template>
          <template slot-scope="scope">
           {{ gridData[scope.$index].dayList[index].dayDate }}
          </template>
        </el-table-column>
               <el-table-column prop="heji" label="月份合计" fixed="right"> </el-table-column>
                <el-table-column prop="huanbi" label="月份环比" fixed="right"> </el-table-column>
                <template slot="empty">
                    <div class="empty">
                        <img class="empty_img" src="@/assets/empty.png" />
                        <div>暂无数据</div>
                    </div>
                </template>
            </el-table>
csharp 复制代码
JS
csharp 复制代码
 gridData: [
                {
                    projectName:'用水情况(吨)',
                    areaName:'商铺',
                    heji:'456',
                    huanbi:'10%',
                    dayList: [
                        {
                            dayName: '1',
                            dayDate: '16'
                        },
                        {
                            dayName: '2',
                            dayDate: '197'
                        },
                        {
                            dayName: '3',
                            dayDate: '198'
                        },
                         {
                            dayName: '4',
                            dayDate: '16'
                        },
                        {
                            dayName: '5',
                            dayDate: '197'
                        },
                        
                    ],
                },
                 {
                    projectName: '用水情况(吨)',
                    areaName: '公寓',
                     heji: '456',
                    huanbi: '10%',
                     dayList: [
                        {
                            dayName: '1',
                            dayDate: '186'
                        },
                        {
                            dayName: '2',
                            dayDate: '187'
                        },
                        {
                            dayName: '3',
                            dayDate: '188'
                        },
                         {
                            dayName: '4',
                            dayDate: '16'
                        },
                        {
                            dayName: '5',
                            dayDate: '197'
                        },
                       
                       
                    ],
                },
              
            ]
相关推荐
机器视觉知识推荐、就业指导13 分钟前
QML 批量创建模块 【Repeater】 组件详解
前端·c++·qml
lmryBC4918 分钟前
golang接口-interface
java·前端·golang
慕斯策划一场流浪25 分钟前
fastGPT—nextjs—mongoose—团队管理之团队列表api接口实现
开发语言·前端·javascript·fastgpt env文件配置·fastgpt团队列表接口实现·fastgpt团队切换api·fastgpt团队切换逻辑
LaoZhangAI1 小时前
【2025最新】Claude免费API完全指南:无需信用卡,中国用户也能用
前端
cypking1 小时前
解决 axios get请求瞎转义问题
vue.js
向阳2561 小时前
SpringBoot+vue前后端分离整合sa-token(无cookie登录态 & 详细的登录流程)
java·vue.js·spring boot·后端·sa-token·springboot·登录流程
hepherd1 小时前
Flask学习笔记 - 模板渲染
前端·flask
LaoZhangAI1 小时前
【2025最新】Manus邀请码免费获取完全指南:5种稳定渠道+3个隐藏方法
前端
经常见1 小时前
浅拷贝与深拷贝
前端