简单封装a-table组件,只做展示使用
公共table组件
javascript
<template>
<a-table :columns="columns" :data-source="data" bordered size="small" :scroll="scroll">
<template #bodyCell="{ column, record, index }">
<template v-if="column.dataIndex === 'index'">
{{ index + 1 }}
</template>
<slot :column="column" :record="record" :index="index"></slot>
</template>
</a-table>
</template>
<script setup lang="ts">
import { watch, ref } from 'vue'
let props = defineProps<{ columns: any; data: any; scroll?: object }>()
const columns = props.columns
const data = ref<any>([])
const scroll = props.scroll || {}
data.value = props.data
watch(() => [...props.data], (now, old) => {
data.value = now
})
</script>
<style scoped></style>
使用组件
数据二次处理。。。等等
javascript
<CommoTable :columns="realitycolumns" :data="realityData" :loading="loading" :scroll="{ y: 300 }"
:pagination="false">
<template #default="{ column, record, index }">
<template v-if="column.dataIndex === 'unitCode'">
{{ unitType[record.unitCode] }}
</template>
</template>
</CommoTable>