前端vben框架中表格table问题汇总

1.template中的代码

<BasicTable @register="registerTable" :canResize="false">
        <!-- 表格左边的插槽 -->
      <template #tableTitle>
        <div class="btn-group">
          <a-button
            ghost
            type="primary"
            preIcon="ant-design:plus-circle-outlined"
            @click="handleCreate"
            >新增</a-button
          >
          <a-button ghost type="success" preIcon="ant-design:vertical-align-bottom-outlined">
            导入</a-button
          >
          <a-button ghost type="warning" preIcon="ant-design:upload-outlined">导出</a-button>
          <a-button ghost type="danger" preIcon="ant-design:delete-outlined">删除</a-button>
        </div>
      </template>
      <!-- 表格右边的插槽 -->
      <!-- <template #toolbar> </template> -->
      <template #action="{ record }">
        <TableAction
          :actions="[
            {
              label: '详情',
              color: 'success',
              onClick: queryDetails.bind(null, record),
            },
            {
              label: '编辑',
              onClick: handleEdit.bind(null, record),
            },
            {
              label: '删除',
              color: 'error',
              popConfirm: {
                title: '是否删除该数据',
                confirm: handleDelete.bind(null, record),
              },
            },
            {
              label: '生成代码',
              color: 'warning',
              onClick: handleCode.bind(null, record),
            },
          ]"
        />
      </template>
    </BasicTable>

2.script中代码:

const [registerTable, { reload }] = useTable({
        // api: list,  // 请求接口
        columns: columns, // 设置表格的表头
        dataSource: dataSources, //表格的数据
        formConfig: {
            labelWidth: 80,
          schemas: searchFormSchema,
          resetFunc: resetFunc,
        },
        pagination: true,   //展示表格下方的分页
        clickToRowSelect: true, //点击当前行多选框不选中,默认是true
        // striped: false,  //是否斑马纹(隔行变色),默认true
        rowSelection: { type: 'checkbox' },   //是否有多选功能
        useSearchForm: true, // 是否有搜索功能
        // showTableSetting: true,  // 是否有刷新和列设置
        bordered: true, // 是否显示边框
        showIndexColumn: true, // 是否显示序号列
        actionColumn: {
          //   width: 240,
          title: '操作',
          dataIndex: 'action',
          slots: { customRender: 'action' },
        },
      });

效果如下:

表格右边设置就是刷新和列设置

3.ts中数据格式:

import { BasicColumn } from '/@/components/Table';
import { FormSchema } from '/@/components/Table';

// 表格表头
export const columns: BasicColumn[] = [
  {
    title: '姓名',
    dataIndex: 'name',
    // slots: { customRender: 'status' },
  },
  {
    title: '性别',
    dataIndex: 'sex',
  },
  {
    title: '字段1',
    dataIndex: 'one',
  },
  {
    title: '字段2',
    dataIndex: 'two',
  },
];

// 搜索框
export const searchFormSchema: FormSchema[] = [
  {
    field: 'one',
    label: '字段1',
    component: 'Input',
    colProps: { span: 5 },
    // componentProps: {
    //   options: [],
    // },
  },
  {
    // 下拉框
    field: 'two',
    label: '字段2',
    component: 'Select',
    colProps: { span: 5 },
    // 下拉框数据
    componentProps: {
      options: [
        {
            label:'aa',
            value:'aa',
        },
        {
            label:'bb',
            value:'bb',
        },
      ],
    },
  },
  {
    field: 'three',
    label: '字段3',
    component: 'Input',
    colProps: { span: 5 },
    // componentProps: {
    //  options: [],
    // },
  },
  {
    field: 'four',
    label: '字段4',
    component: 'Input',
    colProps: { span: 5 },
    // componentProps: {
    //  options: [],
    // },
  },
];

 效果图如下:

 clickToRowSelect: true, 表示点击当前行多选框是否选中,默认是true,效果如下:

4.vben中methods写的位置,官方文档是这么写的:

但是在代码中具体是怎么使用呢?

(1)初始化表格的时候methods写在后面那个大括号中,props写在下面

(2)getSelectRows是个函数,调用这个函数就能拿到表格中选中的数据,可以通过forEach变量:

5.表格中自带搜索功能,那个搜索框的插槽名前面要加form,

eg:表单插槽名time,在表格中的写法是

表单插槽

<template #form-time> </template>

  • 4
    点赞
  • 14
    收藏
    觉得还不错? 一键收藏
  • 13
    评论
可以使用以下步骤在 Vue3 + Vite3 + Typescript 使用 WangEditor 编辑器: 1. 安装 WangEditor。可以使用 npm 或 yarn 安装。 ```bash npm install wangeditor --save # 或者 yarn add wangeditor ``` 2. 在 `main.ts` 引入 WangEditor 和 CSS 文件。 ```typescript import WangEditor from 'wangeditor'; import 'wangeditor/release/wangEditor.css'; const app = createApp(App); app.config.globalProperties.$WangEditor = WangEditor; // 挂载编辑器到全局 app.mount('#app'); ``` 3. 在组件使用 WangEditor。 ```vue <template> <div class="editor-wrapper"> <div ref="editorRef"></div> </div> </template> <script lang="ts"> import { defineComponent, onMounted, ref } from 'vue'; export default defineComponent({ name: 'Editor', setup() { const editorRef = ref<HTMLDivElement>(); onMounted(() => { const editor = new (window as any).$WangEditor(editorRef.value); editor.create(); }); return { editorRef, }; }, }); </script> <style lang="scss"> .editor-wrapper { height: 400px; .w-e-text-container { height: 100%; } } </style> ``` 在 `onMounted` 钩子函数,使用 `new (window as any).$WangEditor` 来创建编辑器实例,并传入编辑器容器的 DOM 节点。调用 `editor.create()` 方法来创建编辑器。 注意:由于 WangEditor 的类型定义文件并不完善,因此可以在 `tsconfig.json` 添加以下配置来避免类型检查报错。 ```json { "compilerOptions": { "skipLibCheck": true } } ``` 这样,就可以在 Vue3 + Vite3 + Typescript 使用 WangEditor 编辑器了。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 13
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值