table表格合并,循环渲染样式

效果

html

html 复制代码
<table>
          <!-- 标题 -->
          <tr>
            <th colspan="100"><el-input style="width: 300px;" v-model="paymentForm.name"></el-input></th>
          </tr>
          <!-- 栏目 -->
          <tr>
            <th colspan="2"></th>
            <th :colspan="item.child.length" v-for="item, i in paymentForm.titleX" :key="i">{{ item.name }}</th>
          </tr>
          <tr>
            <th colspan="2">摘要</th>
            <template v-for="item, i in paymentForm.titleX" :key="i">
              <th v-for="item, k in item.child" :key="k">{{ item }}</th>
            </template>
          </tr>
          <!-- 数据内容 -->
          <template v-for="item, i in paymentForm.titleY" :key="i">
            <!-- 单行展示 -->
            <tr v-show="!item.child" class="red">
              <td colspan="2">{{ item.name }}</td>
              <td v-for="arr, index in item.arr" :key="index">
                <el-input v-model="item.arr[index]"></el-input>
              </td>
            </tr>
            <!-- 多行展示 -->
            <tr v-for="item2, k in item.child" :key="k" v-show="item.child.length">
              <td v-if="k == 0" :rowspan="item.child.length">{{ item.name }}</td>
              <td v-if="item.child.length">{{ item2.name }}</td>
              <td v-for="arr, index in item2.arr" :key="index">
                <el-input v-model="item2.arr[index]"></el-input>
              </td>
            </tr>
          </template>
</table>

js

javascript 复制代码
let paymentForm = ref({
  name: "账户变动情况",
  titleX: [
    { name: '账号1', child: ['基本户建行', '一般户工行1', '一般户工行2', '一般户民生', '农商', '民生', '支付宝'] },
    { name: '账号2', child: ['基本户', '支付宝'] },
    { name: '账号3', child: ['基本户', '支付宝'] },
  ],
  titleY: [
    { name: '昨日结余', arr: [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,] },
    {
      name: '收入',
      child: [
        { name: "订单回款", arr: [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,] },
        { name: "利息", arr: [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,] },
        { name: "其他", arr: [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,] }
      ]
    },
    { name: '收入合计', arr: [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,] },
    {
      name: '支出',
      child: [
        { name: "工资", arr: [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,] },
        { name: "社保", arr: [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,] },
        { name: "还款", arr: [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,] },
        { name: "其他", arr: [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,] }
      ]
    },
    { name: '支出合计', arr: [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,] },
    { name: '本日余额', arr: [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,] },
    { name: '合计', arr: [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,] }
  ]
})

css

css 复制代码
table {
  width: 100%;
  border: 1px solid #ccc;
  text-align: center;
  border-collapse: collapse;

  :deep(.el-input, .el-select, .el-range-editor .el-input__wrapper) {
    width: 100%;
    border: none !important;
  }

  :deep(.el-input__wrapper) {
    box-shadow: none !important;
  }

  tr {

    th {
      padding: 5px 0;
      border: 1px solid #ccc;
      text-align: center;
      min-width: 70px;
    }

    td {
      padding: 5px 0;
      border: 1px solid #ccc;
      text-align: center;
      min-width: 90px;
    }
  }

  .red {
    color: red;
    font-weight: 700;
  }
}
相关推荐
hh随便起个名2 小时前
力扣二叉树的三种遍历
javascript·数据结构·算法·leetcode
我是小路路呀2 小时前
element级联选择器:已选中一个二级节点,随后又点击了一个一级节点(仅浏览,未确认选择),此时下拉框失去焦点并关闭
javascript·vue.js·elementui
JIngJaneIL3 小时前
基于springboot + vue古城景区管理系统(源码+数据库+文档)
java·开发语言·前端·数据库·vue.js·spring boot·后端
敲敲了个代码3 小时前
隐式类型转换:哈基米 == 猫 ? true :false
开发语言·前端·javascript·学习·面试·web
澄江静如练_3 小时前
列表渲染(v-for)
前端·javascript·vue.js
JustHappy4 小时前
「chrome extensions🛠️」我写了一个超级简单的浏览器插件Vue开发模板
前端·javascript·github
Loo国昌4 小时前
Vue 3 前端工程化:架构、核心原理与生产实践
前端·vue.js·架构
sg_knight4 小时前
拥抱未来:ECMAScript Modules (ESM) 深度解析
开发语言·前端·javascript·vue·ecmascript·web·esm
前端白袍4 小时前
Vue:如何实现一个具有复制功能的文字按钮?
前端·javascript·vue.js
new code Boy5 小时前
escape谨慎使用
前端·javascript·vue.js