干巴爹兔的博客 干巴爹兔的博客
首页
  • 前端文章

    • JavaScript
    • HTML
    • Vue
  • 学习笔记

    • JavaScript教程
    • React学习笔记
    • Electron学习笔记
  • 开源项目

    • cloud-app-admin
    • 下班了吗Vscode插件
    • Subversion变更单插件
  • Server

    • Django
  • 学习笔记

    • MySQL学习笔记
  • 运维

    • 服务器部署
    • Linux
  • 日常学习

    • 学习方法
关于
收藏
友链
  • 分类
  • 标签
  • 归档
GitHub (opens new window)

干巴爹兔

卑微的前端打工人
首页
  • 前端文章

    • JavaScript
    • HTML
    • Vue
  • 学习笔记

    • JavaScript教程
    • React学习笔记
    • Electron学习笔记
  • 开源项目

    • cloud-app-admin
    • 下班了吗Vscode插件
    • Subversion变更单插件
  • Server

    • Django
  • 学习笔记

    • MySQL学习笔记
  • 运维

    • 服务器部署
    • Linux
  • 日常学习

    • 学习方法
关于
收藏
友链
  • 分类
  • 标签
  • 归档
GitHub (opens new window)
  • JavaScript文章

  • 学习笔记

  • 开源项目

    • cloud-app-admin
    • could-app-admin前端组件

      • AsyncSelect异步加载下拉组件
      • Card卡片组件
      • Panel展示组件
      • CForm表单组件
      • SearchFilter组件
      • CTable表格组件
        • 组件介绍
        • 引入组件
        • 参数配置
        • 类型
        • 代码示例
        • More
    • 下班了吗Vscode插件

    • Subversion变更单插件

  • HTML

  • Vue

  • 前端
  • 开源项目
  • could-app-admin前端组件
干巴爹兔
2022-10-10
目录

CTable表格组件

# 组件介绍

这是一个基于el-table封装,使用json数据配置式的表格组件,支持表格列排序、列筛选、新增、刷新、删除等常用操作,可传入插槽。

# 引入组件

import { App } from "vue";
import CTable from "./CTable.vue";

export function setupRegisterGlobComp(app: App) {
  app.component("CTable", CTable);
}
1
2
3
4
5
6

# 参数配置

额外参数 类型 必填 说明
columns CTableColumn 必填 表格核心配置项
tableData Any 必填 表格数据
showHeader Boolean 非必填 用于展示顶部操作栏

# 类型

import type { TableColumnCtx } from "element-plus/es/components/table/src/table-

export type CTableColumn<T> = Partial<TableColumnCtx<T>> & {
  scoped?: string; // 用于插槽,类似于原有的el-table内的嵌套
  show?: boolean; // 是否展示该列
  locked?: boolean; // 是否能够移动此列
  initialWidth?: string; // 列初始宽度
};
1
2
3
4
5
6
7
8

# 代码示例

<script setup lang="ts">
// id title content
const dataSource = ref([
  {
    id: 1,
    title: "title1",
    content: "content1"
  },
  {
    id: 2,
    title: "title2",
    content: "content2"
  }
]);
const articleColumns = computed(() => {
  return [
    {
      type: "selection",
      show: true,
      width: "55"
    },
    {
      prop: "id",
      show: true,
      label: "ID",
      width: "80"
    },
    {
      prop: "title",
      show: true,
      label: "Title",
      width: "180"
    },
    {
      prop: "content",
      show: true,
      label: "Content",
      showOverflowTooltip: true
    },
    {
      prop: "actions",
      show: true,
      label: "Actions",
      fixed: "right",
      scoped: "actions",
      width: "150"
    }
  ];
});
</script>

<template>
  <div class="relative w-full">
    <div class="p-[8px] absolute w-full">
      <c-table
        :table-data="dataSource"
        :show-header="true"
        :columns="articleColumns"
        header-align="right"
        stripe
        style="width: 100%"
        @selection-change="() => {}"
      >
        <template #options>
          <el-button icon="refresh" circle />
          <el-button type="primary" icon="plus" circle />
          <el-button type="danger" icon="delete" circle />
        </template>
        <template #actions>
          <el-button size="small">Edit</el-button>
          <el-button size="small" type="danger">Delete</el-button>
        </template>
      </c-table>
    </div>
  </div>
</template>

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77

table-example1

# More

精力有限(懒),更多的使用方式可以查看文章列表页或Table源码自行探索,使用上有困难的可以在issue上进行咨询我

编辑 (opens new window)
上次更新: 2022/10/10, 09:49:29
SearchFilter组件
Vscode插件配置项监听

← SearchFilter组件 Vscode插件配置项监听→

最近更新
01
使用Vscode开发一个小插件
10-21
02
Vscode插件配置项监听
10-18
03
使用has属性构造必填效果
10-14
更多文章>
Theme by Vdoing | Copyright © 2020-2023 互联网ICP备案: 闽ICP备18027236号
  • 跟随系统
  • 浅色模式
  • 深色模式
  • 阅读模式