VUE3的Vben的TABLE的列表的使用

列表参考的文档有2个, Vben里的FORM + TABLE
TABLE里面通过配置,可以自带有搜索和列表和分页, 以用户列表为例, 先贴上template端的代码

<template>
  <div>
    <BasicTable
      title="列表测试-副标题"
      ref="tableRef"
      @register="registerTable"
      :searchInfo="searchInfo"
    >
      <template #toolbar>
        <a-button type="primary" @click="handleEdit"> 新增用户 </a-button>
      </template>
      <template #bodyCell="{ column, record }">
        <template v-if="column.key === 'action'">
          <TableAction :actions="createActions(record)" />
        </template>
      </template>
    </BasicTable>
    <test1Modal @register="register1" @success="handleSuccess" />
    <test2Modal @register="register2" @success="handleSuccess" />
  </div>
</template>

BasicTable是TABLE的一个组件, registerTable用于注册 useTable,如果需要使用useTable提供的 api,必须将 registerTable 传入组件的 onRegister, 以下代码是完成注册的方式:

    const [registerTable] = useTable({
    api: accountListsApi, //接口api
    columns: columns, //列数组,渲染table的列表
    showIndexColumn: false, //是否显示序号列
    actionColumn: {
      //表格右侧操作列配置 BasicColumn
      width: 160,
      title: '操作',
      dataIndex: 'action',
      // slots: { customRender: 'action' },
    },
    formConfig: {
      //表单配置,参考表单组件的 Props
      labelWidth: 120,
      schemas: searchFormSchema,
      autoSubmitOnEnter: true,
    },
    handleSearchInfoFn(info) {
      //开启表单后,在请求之前处理搜索条件参数
      console.log('handleSearchInfoFn', info);
      return info;
    },
    useSearchForm: true, //使用搜索表单
    scroll: { y: '100%' },
    pagination: true, //分页信息配置,为 false 不显示分页	
  });

通过tableRef的方式拿到TABLE的对象, 然后才可以使用METHODS里面的方法
把代码贴出来

  const tableRef = ref<Nullable<TableActionType>>(null);
  function getTableAction() {
    const tableAction = unref(tableRef);
    if (!tableAction) {
      throw new Error('tableAction is null');
    }
    return tableAction;
  }
  //使用方法
  getTableAction().setTableData();
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值