二次封装elementTable

父组件

<a_table :listData="userList" :propList="propList">
   <template #status="scope">
      <el-button :type="scope.row.enable ? 'success' : 'error'">
          {{ scope.row.enable ? '启用' : '禁用' }}
      </el-button>
   </template>
</a_table>


const userList = [
    {
        cellphone: 13666666666,
        createAt: "2023-06-23T07:40:02.000Z",
        departmentId: 4745,
        enable: 1,
        id: 177044190,
        name: "lebron",
        realname: "lebron111",
        roleId: 1,
        updateAt: "2023-06-23T07:45:09.000Z"
    },
    {
        cellphone: 13666666666,
        createAt: "2023-06-23T07:40:02.000Z",
        departmentId: 4745,
        enable: 1,
        id: 177044191,
        name: "lebron",
        realname: "lebron111",
        roleId: 1,
        updateAt: "2023-06-23T07:45:09.000Z"
    }
]
//表头
const propList = [
    { prop: 'name', label: '用户名', minWidth: '100' },
    { prop: 'realname', label: '真实姓名', minWidth: '100' },
    { prop: 'cellphone', label: '手机号码', minWidth: '120' },
    { prop: 'enable', label: '状态', minWidth: '100', slotName: 'status' },
    { prop: 'createAt', label: '创建时间', minWidth: '250', slotName: 'createAt' },
    { prop: 'updateAt', label: '更新时间', minWidth: '250', slotName: 'updateAt' }
]

子组件

<template>
    <div class="hy-table">
        <!-- listData 内容 -->
        <el-table :data="listData" style="width: 100%"
            :header-cell-style="{ backgroundColor: '#f6f7f9', 'text-align': 'center' }">
            <!-- 头部 -->
            <template v-for="propItem in propList" :key="propItem.prop">
                <el-table-column v-bind="propItem" align="center">
                    <template #default="scope">
                        <slot :name="propItem.slotName" :row="scope.row">
                            {{ scope.row[propItem.prop] }}
                        </slot>
                    </template>
                </el-table-column>
            </template>
        </el-table>
    </div>
</template>

<script lang="ts" setup>
import { onMounted, reactive, ref } from 'vue'
const props = defineProps({

    listData: {
        type: Array,
        require: true
    },
    propList: {
        type: Array,
        require: true
    },
    data: {}
})
</script>

<style scoped></style>

  • 2
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值