vue element table表头垂直表格(新增封装一个垂直表格的组件)

3 篇文章 0 订阅

对话框中弹出查看信息,打开时表格,要求是表头在左侧

 <table class="tableInfo" :model="editForm" id="printTest">
            <thead></thead>
            <tbody>
              <tr>
                <td>日报类型</td>
                <td>{{editForm.daily_type | filterType}}</td>
              </tr>
              <tr>
                <td>开始时间</td>
                <td>{{editForm.start_time  | formatTimer('hours')}}</td>
              </tr>
              <tr>
                <td>结束时间</td>
                <td>{{editForm.end_time | formatTimer('hours') }}</td>
              </tr>
              <tr>
                <td>今日内容</td>
                <td>{{editForm.content}}</td>
              </tr>
              <tr>
                <td>计划</td>
                <td>{{editForm.plan}}</td>
              </tr>
            </tbody>
          </table>

效果
在这里插入图片描述

--------------------------------------手动的华丽丽的的分割线------------------------------------------------------
最近封装了一个带插槽的垂直表头的table组件
效果如图
在这里插入图片描述
封装的部分全部代码

<template>
  <div class="table_detail">
    <div class="list" v-for="item in detailData" :key="item.value">
      <div class="label">
        <el-badge
          :value="1"
          class="item"
          type="primary"
          v-if="item.label === '扣分项' || item.label === '加分项'"   //这里是动态传表头进去
        />
        {{ item.label }}
      </div>
      <div class="text">
        <template v-if="$scopedSlots[item.prop]">
          <slot :name="item.prop" :files="item.text"></slot>
        </template>
        <template v-else>{{ item.text }}</template>
      </div>
    </div>
  </div>
</template>
<script>
export default {
  name: "table-detail",
  props: {
    detailData: {
      type: Array,
      default: () => []
    }
  },
  data() {
    return {
      visible: false
    }
  }
}
</script>
<style lang="scss">
.table_detail {
  width: auto;
  height: auto;
  margin: 0 10px 0 10px;
  border: 1px solid #ebeef5;
  border-bottom: none;
  .list {
    display: flex;
    justify-content: space-between;
    border-bottom: 1px solid #ebeef5;
    // font-size: 16px;
    .label {
      width: 95px;
      border-right: 1px solid #ebeef5;
      padding: 10px 10px 10px 0;
      text-align: right;
      font-weight: 400;
    }
    .text {
      flex: 1;
      text-align: left;
      padding: 10px 30px 10px 10px;
      font-weight: 500;
      word-wrap: break-word; //超出文本行自动换行
    word-break: break-all; //超出文本行自动换行
    overflow: hidden; //超出文本行自动换行
    }
  }
}
</style>

然后使用部分,先局内引入注册
然后使用

  <table-detail :detailData="companyDetail">
  // 这部分使我们自己要用的预览文件的部分,不用的话可以不用写
            <template v-slot:file="{ files }">
              <app-upload
                :upload="new Upload(upload)"
                is-download
                is-preview
                is-view
                disabled
              />
              <ul>
                <li v-for="(file, i) in files" :key="i">
                  {{ file.url }}
                  <el-link
                    type="primary"
                    :href="file ? file.url : ''"
                    target="_blank"
                    >预览</el-link
                  >
                  <el-link type="primary" @click="download(file)">下载</el-link>
                </li>
              </ul>
            </template>
          </table-detail>

在data 里面定义 companyDetail: [],
然后在methods里面获取到数据之后赋值即可

          this.companyDetail = [
            {
              label: `${this.labelTitle}项`,
              text: res.indexTitle
            },
            {
              label: `${this.labelTitle}值`,
              text: res.score
            },
            {
              label: `${this.labelTitle}时间`,
              text: this.$formatDate(res.reportTime, "YYYY.MM.DD", "YYYYMMDD")
            },
            {
              label: `${this.labelTitle}单位`,
              text: res.orgName
            },
            {
              label: `${this.labelTitle}原因`,
              text: res.description
            },
            {
              label: "申诉理由",
              text: res.reason
            },
            {
              label: "附件",
              prop: "file",
              text: files
            }
          ]

大致如上

  • 0
    点赞
  • 10
    收藏
    觉得还不错? 一键收藏
  • 2
    评论
如果你想使用第三方的 Vue 3 表格组件封装一个表格,可以按照以下步骤进行操作: 1. 安装所需的表格组件。以 Element Plus 为例,你可以使用以下命令进行安装: ``` npm install element-plus ``` 2. 在你的 Vue 3 项目中导入并注册表格组件。在你的 main.js 文件中添加以下代码: ```javascript import { createApp } from 'vue'; import ElementPlus from 'element-plus'; import 'element-plus/dist/index.css'; import App from './App.vue'; const app = createApp(App); app.use(ElementPlus); app.mount('#app'); ``` 3. 创建一个新的 Vue 组件,用于封装表格。在这个组件中,你可以使用 Element Plus 提供的 Table 组件。 ```vue <template> <el-table :data="tableData"> <el-table-column v-for="column in tableColumns" :key="column.prop" :prop="column.prop" :label="column.label"> </el-table-column> </el-table> </template> <script> export default { data() { return { tableColumns: [ { prop: 'name', label: 'Name' }, { prop: 'age', label: 'Age' }, { prop: 'city', label: 'City' } ], tableData: [ { id: 1, name: 'John Doe', age: 25, city: 'New York' }, { id: 2, name: 'Jane Smith', age: 30, city: 'San Francisco' }, { id: 3, name: 'Bob Johnson', age: 35, city: 'Los Angeles' } ] }; } }; </script> ``` 在这个示例中,我们使用了 Element Plus 的 Table 组件,并通过 `tableColumns` 和 `tableData` 来动态渲染表格的列和数据。 你可以根据具体的表格组件的文档和需求,进一步自定义和扩展你的表格组件

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值