Naive UI之BasicTable 序号 和 render

这段内容展示了如何在Vue应用中使用Naive UI库来渲染带有选择框、序号、标题和类型信息的表格。代码片段定义了表格列的配置,包括自定义渲染类型字段,同时提供了一个异步加载数据的方法`loadDataTable`,该方法用于获取并更新表格数据。

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

 columns:(表格项)

import { NText } from 'naive-ui';
import { h } from 'vue';
const statusOptions = {
  1: { text: '种类1', type: '' },
  2: { text: '种类2', type: '' },
};
export const columns = [
  { type: 'selection', key: 'selection' },//复选框列
{
    title: '序号',
    width: 40,
    align: 'center',
    render: (text: any, record: any, index: any) => {
      return record + 1;
    },
  },
  {
    title: '标题',
    key: 'content',
    width: 100,
    align: 'center',
  },
  {
    title: '类型',
    key: 'type',
    width: 100,
    align: 'center',
    render(row) {
      return h(
        NText,
        {
          type: statusOptions[row.type].type,
        },
        { default: () => statusOptions[row.type].text }
      );
    },
  },
];

request请求

const loadDataTable = async (res) => {
    tableData.value = await getList({ ...params.value, ...res });
    return tableData.value;
  };

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值