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;
  }
}
相关推荐
知识分享小能手8 小时前
微信小程序入门学习教程,从入门到精通,微信小程序常用API(上)——知识点详解 + 案例实战(4)
前端·javascript·学习·微信小程序·小程序·html5·微信开放平台
蓝莓味的口香糖9 小时前
【JS】什么是单例模式
开发语言·javascript·单例模式
reembarkation11 小时前
自定义分页控件,只显示当前页码的前后N页
开发语言·前端·javascript
Roye_ack11 小时前
【项目实战 Day9】springboot + vue 苍穹外卖系统(用户端订单模块 + 商家端订单管理模块 完结)
java·vue.js·spring boot·后端·mybatis
gerrgwg11 小时前
React Hooks入门
前端·javascript·react.js
汉字萌萌哒12 小时前
【 HTML基础知识】
前端·javascript·windows
北城以北888814 小时前
Vue--Vue基础(二)
前端·javascript·vue.js
FuckPatience15 小时前
Vue 组件定义模板,集合v-for生成界面
前端·javascript·vue.js
有梦想的攻城狮16 小时前
从0开始学vue:vue和react的比较
前端·vue.js·react.js
silent_missile18 小时前
vue3父组件和子组件之间传递数据
前端·javascript·vue.js