Descriptions 官网:描述列表 Descriptions - Ant Design Vue
<template>
<Descriptions :column="2">
<Descriptions.Item
v-for="(item, index) in myData"
:key="index"
:label="item.title"
>
<div>{{ `${myDataObj[item.dataIndex] ?? "-"}` }}</div>
</Descriptions.Item>
</Descriptions>
</template>
<script lang="ts" setup>
import { computed, ref, onMounted } from "vue";
import { Descriptions } from "ant-design-vue";
import { basicInfo, type } from "./Demo";
const myDataObj: any = ref({
name: "张三",
phone: "123456789",
address: "北京市",
});
const myData = computed(() => {
let arr = basicInfo.value.filter((item) => {
return item.ifShow(type.value);
});
return arr;
});
onMounted( () => {
type.value = 2;
});
</script>
<style lang="scss" scoped></style>
Demo.ts
export const type: any = ref('');
// 基本信息
export const basicInfo = ref([
{
dataIndex: 'name',
title: '姓名',
},
{
dataIndex: 'phone',
title: '电话',
ifShow: (step) => {
return type == 1 ? true : false;
},
},
]);