vue 3.2 setup 详情table基础版 动态设置 x 列展示支持slot

本文介绍了如何使用Vue.js创建一个可配置列数的详细表格组件,展示动态数据并以模板化方式显示不同列的内容。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

<template>
  <div class="detail-table">
    <div
      v-for="(row, key, index) in config"
      :key="key"
      class="detail-item"
      :style="{ width: `${cellWidth}` }"
      :class="[
        'detail-item',
        {
          'border-top': index < columnsPerRow
        }
      ]"
    >
      <div class="detail-label">{{ row }}</div>
      <div class="detail-value">
        <slot :name="key" :row="data">
          {{ data[key] || '' }}
        </slot>
      </div>
    </div>
  </div>
</template>

<script setup name="DetailTable">
const props = defineProps({
  data: {
    type: Object,
    required: true,
    default: () => {}
  },
  config: {
    type: Object,
    default: () => {}
  },
  columnsPerRow: {
    type: Number,
    required: false,
    default: 3
  }
})
const cellWidth = computed(() => {
  return `${(100 / props.columnsPerRow).toFixed(1)}%`
})
</script>

<style lang="scss" scoped>
.detail-table {
  display: flex;
  flex-direction: row;
  border-left: 1px solid #d9d9d9;
  flex-wrap: wrap;

  .detail-item {
    min-height: 38px;
    border-bottom: 1px solid #d9d9d9;
    display: flex;
  }

  .detail-label {
    width: 130px;
    padding: 0 10px;
    text-align: center;
    font-weight: bold;
    border-right: 1px solid #d9d9d9;
    background: #f3f3f3;
    display: flex;
    align-items: center;
    justify-content: center;
  }

  .detail-value {
    display: flex;
    align-items: center;
    flex: 1;
    border-right: 1px solid #d9d9d9;
    background: #fff;
    margin-left: 10px;
    word-wrap: break-word;
    word-break: break-all;
  }
}

.border-top {
  border-top: 1px solid #d9d9d9;
}
</style>

html

 <detail-table :config="basic" :data="info" :columnsPerRow="3">
   <template #status="{ row }">
       {{ $formatDict(row.status, transfer_out_order_status) }}
     </template>
 </detail-table>
 
 script
 
 const basic = {
  code: '调拨出库单号',
  type: '调拨类型',
  status: '状态',
  outOcName: '运营中心',
  outDcName: '调出分发中心',
  enterDcName: '调入分发中心',
  deliveryAddress: '提货地址',
  deliveryContactor: '提货联系人'
  }
 function getDetail() {
  spinning.value = true
  getTransferOutOrder(selectedRow.value.id)
    .then(({ data }) => {
      info.value = data
    })
    .finally(() => {
      spinning.value = false
    })
}
getDetail()
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

web_Hsir

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值