插槽
<template #status="{ text: status }"> <span> <a-tag :color="status == '0' ? 'blue' : 'red'">{{ status == '0' ? '启用' : '停用' }}</a-tag> </span></template>
table 组件使用
<template> <a-table :data-source="userInfoData" :pagination="false" :columns="columns"> <template #status="{ text: status }"> <span> <a-tag :color="status == '0' ? 'blue' : 'red'">{{ status == '0' ? '启用' : '停用' }}</a-tag> </span> </template> <template #action="{ record }"> <span> <a-button type="primary" danger>删除</a-button> <a-button type="primary" @click="onEdit">编辑</a-button> <a-button type="primary" danger>密码重置</a-button> <a-button :type="record.status == '0' ? 'success' : 'danger'">{{ record.status == '0' ? '启用' : '停用' }}</a-button> </span> </template> </a-table></template><script lang="ts" setup> import { storeToRefs } from 'pinia'; import { onBeforeMount } from 'vue'; import usePermissionManagementStore from '/@/store/modules/management'; const managementStore = usePermissionManagementStore(); const { userInfoData } = storeToRefs(managementStore); const { onEdit, getUserInfoData } = managementStore; /** *table 属性类型定义 */ type ColumnType = { title: string; dataIndex: string; key: string; class?: string; slots?: Object; width?: number; align?: 'center' | 'left' | 'right'; fixed?: 'left' | 'right'; slots?: Object; filters?: { text: string; value: string; children?: { text: string; value: string; }[]; }[]; onFilter?: (value: string, record: ConceptData) => boolean; sortDirections?: string[]; defaultSortOrder?: string; filterMultiple?: string[] | boolean; filterDropdownVisible?: boolean; }; const columns: ColumnType[] = [ { key: 'userid', title: '序号', dataIndex: 'userid', width: 60, fixed: 'right', }, { key: 'username', title: '用户名', dataIndex: 'username', width: 60, }, { key: 'realname', title: '真实姓名', dataIndex: 'realname', width: 60, }, { key: 'telephone', title: '电话', dataIndex: 'telephone', width: 60, }, { key: 'status', title: '状态', dataIndex: 'status', width: 60, slots: { customRender: 'status' }, }, { key: 'last_ip', title: '最后登录IP', dataIndex: 'last_ip', width: 60, }, { key: 'last_login_time', title: '最后登陆时间', dataIndex: 'last_login_time', width: 60, }, { key: 'action', title: '操作', dataIndex: 'action', align: 'center', width: 100, slots: { customRender: 'action' }, }, ]; onBeforeMount(async () => { await getUserInfoData(); });</script>
参考
【1】https://2x.antdv.com/docs/vue/introduce-cn