Table实现将表头放在右侧,数据在左侧

23 篇文章 0 订阅

效果图:在这里插入图片描述

这里使用Vue3.0写法实现这种效果
完整代码:

<script setup>
import { ref, computed, onMounted } from "vue"

const styleObject = ref({})
const s_showByRow = ref(false)
const tableData = ref([
  { key: "树种", value: "侧柏" },
  { key: "行政村", value: "**村" },
  { key: "镇场", value: "**镇" },
  { key: "X坐标", value: "447562.46587" },
  { key: "Y坐标", value: "3956877.25635" },
  { key: "小班", value: "8" },
  { key: "林班", value: "12" },
  { key: "林分编号", value: "*****1255" },
  { key: "单株编号", value: "*****12345" },
])

onMounted(() => {
  styleObject.value = { width: "600px" }
})

const rowCount = computed(() => {
  return Math.ceil(tableData.value.length / 2)
})
</script>
<template>
  <div class="animate__animated animate__fadeIn root">
    <button type="button" class="button blue larrow" @click="$router.replace('/')">返回主页</button>

    <table v-if="s_showByRow" class="mailTable" :style="styleObject">
      <tr v-for="index in rowCount" :key="index">
        <td class="column">{{ tableData[index * 2 - 2].key }}</td>
        <td>{{ tableData[index * 2 - 2].value }}</td>
        <td class="column">{{ tableData[index * 2 - 1] !== undefined ? tableData[index * 2 - 1].key : "" }}</td>
        <td>{{ tableData[index * 2 - 1] !== undefined ? tableData[index * 2 - 1].value : "" }}</td>
      </tr>
    </table>
    <table v-else class="mailTable" :style="styleObject">
      <tr v-for="index in rowCount" :key="index">
        <td class="column">{{ tableData[index - 1].key }}</td>
        <td>{{ tableData[index - 1].value }}</td>
        <td class="column">
          {{ tableData[rowCount + index - 1] !== undefined ? tableData[rowCount + index - 1].key : "" }}
        </td>
        <td>{{ tableData[rowCount + index - 1] !== undefined ? tableData[rowCount + index - 1].value : "" }}</td>
      </tr>
    </table>
  </div>
</template>

<style scoped lang="scss">
.mailTable,
.mailTable tr,
.mailTable tr td {
  border: 1px solid #e6eaee;
}
.mailTable {
  font-size: 12px;
  color: #71787e;
}
.mailTable tr td {
  border: 1px solid #e6eaee;
  width: 150px;
  height: 35px;
  line-height: 35px;
  box-sizing: border-box;
  padding: 0 10px;
}
.mailTable tr td.column {
  background-color: #eff3f6;
  color: #393c3e;
}
</style>

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
锁定表头及固定左边列,原生JS原创代码 需要注意的问题: 1.表格的宽度以及表格每一列的宽度需要固定(特殊情况除外:当表格列数少并且表格总宽度明显小于表格父容器的宽度时,也就是表格列不存在自动换行的问题) 2.表格父容器尺寸大小改变时,需要调用 setBoxSize 方法,目的是判断父容器是否出现滚动条 1.1 修正了对IE6、IE7的兼容问题 1.2 修正了固定行、列的样式问题 1.3 IE6/IE7浏览器 不启用该功能 1.4 增加了拆分线, 修正了重复生成锁定行列的问题以及生成错位的问题, 修正了行、列事件无法复制的问题, 增加了IE6/IE7/IE8 启用设置参数(ieLowVersionEnabled: true|false) ,默认不启用, 注:IE6/7/8锁定表头 由于兼容性问题,有些情况下会有一些错位的问题 1.5 增加了 显示/隐藏功能,修正了非IE浏览器下列宽错位问题 1.6 修正了当有合并单元格时,锁定单元格错位的问题,修正了表格行数较多时的性能问题 1.7 表格单元格可以不指定宽度(锁定时,取实际的单元格宽度),当单元格的左右两边的borderWidth不一样时,会有一些错位 若单元格宽度是固定的,可以在第3个参数(config)中指定 isFixedSize:true 修正表头列未锁定的Bug 1.8 修正表格含有thead时的样式丢失问题,以及行数设置问题,修正thead/tbody行归属问题 1.9 移除tbTopLeft的边框线 修正表格cellpadding/cellspacing的设置问题 修复Firefox下的padding导致的错位问题 修复thead复制没有底部分割线的问题 修复thead复制时无背景色的问题 增加复选框同步功能(如果是JS代码设置复选框选中,需要调用 .setCheckBoxSync()方法) .setCheckBoxSync 方法参数说明:4种参数 1) 复选框控件(html object)数组 2) 复选框控件(html object) 3) 复选框控件ID (string) 4) 空参数(尽量不用空参数)

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值