实战:vue3.0 ant-design table表头国际化i18n问题

本文展示了如何在Ant Design Vue的表格组件中实现表头的国际化,并自定义操作列,包括查看和编辑功能。通过使用`$t`函数进行多语言渲染,以及设置`customRender`来改变特定列的显示内容。

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

<a-table
   :columns="columns"
   :dataSource="dataSource"
   :pagination="false"
   :loading="loading"
   :scroll="{ x: 1100, y: 300 }"
 >
 	// 表头国际化设置
   <template #headerCell="{ column }">
     <template v-for="(item, index) in columns" :key="index">
       <span v-if="column.nameI18n && column.dataIndex === item.dataIndex">
       {{ $t(column.nameI18n) }}
       </span>
     </template>
   </template>
   // 操作栏
   <template #bodyCell="{ column, record }">
     <template v-if="column.dataIndex === 'operation'">
       <a-button type="link" @click="check(record)">查看</a-button>
       <a-button type="link" @click="edit(record)">编辑</a-button>
     </template>
   </template>
 </a-table>

定义的表头数据:

// nameI18n 为template中渲染的字段
// teachID 为多语言文件中设置的国际化标识
const columns = [
  {
    title: '是否启用',
    dataIndex: 'status',
    nameI18n: 'isEnable',
    customRender: (text) => {
      return text == 1 ? '启用' : '禁用'
    },
    ellipsis: true,
    width: '180px'
  },
  {
    title: '操作',
    dataIndex: 'operation',
    fixed: 'right',
    align: 'center',
    width: 300
  }
]

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值