element -ui 实现纵向表格,单元格包裹多行

css 复制代码
  <el-table
                :data="tableData1"
                :cell-style="{ 'text-align': 'center' }"
                :header-cell-style="{
                    textAlign: 'center',
                    background: '#E5E5E5',
                    'border-color': '#B3B3B3',
                    height: '38px',
                    lineHeight: '38px',
                }"
                border
                class="no-header"
                :cell-class-name="getCellClass"
                :header-cell-class-name="getCellClass"
                style="width: 30%"
            >
                <el-table-column prop="name" width="180"> </el-table-column>
                <el-table-column>
                    <template slot-scope="scope">
                        <div
                            v-for="(temp, index) in scope.row.temperatures"
                            :key="index"
                        >
                            {{ temp.type }}
                        </div>
                    </template>
                </el-table-column>
                <el-table-column>
                    <template slot-scope="scope">
                        <div
                            v-for="(temp, index) in scope.row.temperatures"
                            :key="index"
                        >
                            {{ temp.value }}°C
                        </div>
                    </template>
                </el-table-column>
            </el-table>

data定义的数据,处理数据按照这个格式处理即可:

python 复制代码
   tableData1: [
                {
                    name: "B1",
                    temperatures: [
                        { type: "最高温", value: 30 },
                        { type: "最低温", value: 10 },
                        { type: "平均温", value: 20 },
                    ],
                },
                {
                    name: "B2",
                    temperatures: [
                        { type: "最高温", value: 35 },
                        { type: "最低温", value: 15 },
                        { type: "平均温", value: 25 },
                    ],
                },
            ],

调用边框的方法:

python 复制代码
 methods: {
        getCellClass() {
            return "table-cell-border";
        },
sql 复制代码
<style scoped>
::v-deep .table-cell-border {
    border: 1px solid #b3b3b3; /* 调整边框的颜色和样式 */
}
::v-deep .no-header .el-table__header-wrapper {
    display: none;
}
</style>

成果:

相关推荐
cmd1 分钟前
吃透 ES6 Generator:yield/next/yield* 核心用法详解
前端·javascript
我叫黑大帅2 分钟前
🎯 DOM 事件:onclick VS addEventListener('click')区别
前端·javascript·面试
踩着两条虫5 分钟前
AI 驱动的 Vue3 应用开发平台 深入探究(二十二):CLI与工具链之开发与生产工作流
前端·vue.js·ai编程
Ankkaya8 分钟前
大师助我,electron-hiprint 源码梳理
前端·vue.js
风止何安啊8 分钟前
🪝 别再重复造轮子了!教你偷懒:在 React 自定义 Hook
前端·react.js·面试
踩着两条虫8 分钟前
AI 驱动的 Vue3 应用开发平台 深入探究(二十三):API与参考之Engine API 参考
前端·vue.js·ai编程
Moment10 分钟前
开源一年,我的 AI 全栈项目 AI 协同编辑器终于有 1.1 k star了 😍😍😍
前端·后端·面试
爱学习的小囧10 分钟前
VCF 集群部署灵活组合:单节点与高可用配置完全指南
java·服务器·前端
967713 分钟前
AJAX和Axios理解和关系
前端·ajax·okhttp
sg_knight16 分钟前
Claude Code 如何辅助定位 Bug 和问题代码
java·前端·bug·ai编程·claude·code·claude-code