Skip to content

列表 Table

列表组件

基础用法

Show Code
vue
<script lang="ts" setup>
import { ref } from 'vue'
import type { ITableOption } from 'm-eleplus-crud'

const tableOption = ref<ITableOption>({
  border: true,
  column: [
    {
      label: '名字',
      prop: 'name',
    },
    {
      label: '性别',
      prop: 'sex',
      type: 'select',
      dicData: [
        {
          label: '男',
          value: 1,
        },
        {
          label: '女',
          value: 2,
        },
      ],
    },
  ],
})

const tableData = ref([
  {
    name: 'ZhangSan',
    sex: 1,
  },
  {
    name: 'LiSi',
    sex: 2,
  },
])
</script>

<template>
  <div style="width: 100%">
    <MTable :option="tableOption" :data="tableData" />
  </div>
</template>

索引

Show Code
vue
<script lang="ts" setup>
import { ref } from 'vue'
import type { ITableOption } from 'm-eleplus-crud'

const tableOption = ref<ITableOption>({
  border: true,
  column: [
    {
      type: 'index',
    },
    {
      label: '名字',
      prop: 'name',
    },
    {
      label: '性别',
      prop: 'sex',
      type: 'select',
      dicData: [
        {
          label: '男',
          value: 1,
        },
        {
          label: '女',
          value: 2,
        },
      ],
    },
  ],
})

const tableData = ref([
  {
    name: 'ZhangSan',
    sex: 1,
  },
  {
    name: 'LiSi',
    sex: 2,
  },
])
</script>

<template>
  <div style="width: 100%">
    <MTable :option="tableOption" :data="tableData" />
  </div>
</template>

单选

Show Code
vue
<script lang="ts" setup>
import { ref } from 'vue'
import type { ITableOption } from 'm-eleplus-crud'

const tableOption = ref<ITableOption>({
  border: true,
  column: [
    {
      type: 'single',
      width: 50,
    },
    {
      label: '名字',
      prop: 'name',
    },
    {
      label: '性别',
      prop: 'sex',
      type: 'select',
      dicData: [
        {
          label: '男',
          value: 1,
        },
        {
          label: '女',
          value: 2,
        },
      ],
    },
  ],
})

const tableData = ref([
  {
    name: 'ZhangSan',
    sex: 1,
  },
  {
    name: 'LiSi',
    sex: 2,
  },
])

const selectData = ref<any>([])
</script>

<template>
  <div style="width: 100%">
    <MTable
      v-model:select="selectData"
      :option="tableOption"
      :data="tableData"
    />
  </div>
</template>

多选

Show Code
vue
<script lang="ts" setup>
import { ref } from 'vue'
import type { ITableOption } from 'm-eleplus-crud'

const tableOption = ref<ITableOption>({
  border: true,
  column: [
    {
      type: 'selection',
      width: 50,
    },
    {
      label: '名字',
      prop: 'name',
    },
    {
      label: '性别',
      prop: 'sex',
      type: 'select',
      dicData: [
        {
          label: '男',
          value: 1,
        },
        {
          label: '女',
          value: 2,
        },
      ],
    },
  ],
})

const tableData = ref([
  {
    name: 'ZhangSan',
    sex: 1,
  },
  {
    name: 'LiSi',
    sex: 2,
  },
])

const selectData = ref<any>([])
</script>

<template>
  <div style="width: 100%">
    <MTable
      v-model:select="selectData"
      :option="tableOption"
      :data="tableData"
    />
  </div>
</template>

自定义列

Show Code
vue
<script lang="ts" setup>
import { ref } from 'vue'
import type { ITableOption } from 'm-eleplus-crud'

const tableOption = ref<ITableOption>({
  border: true,
  column: [
    {
      label: '名字',
      prop: 'name',
    },
    {
      label: '性别',
      prop: 'sex',
      type: 'select',
      dicData: [
        {
          label: '男',
          value: 1,
        },
        {
          label: '女',
          value: 2,
        },
      ],
    },
  ],
})

const tableData = ref([
  {
    name: 'ZhangSan',
    sex: 1,
  },
  {
    name: 'LiSi',
    sex: 2,
  },
])
</script>

<template>
  <div style="width: 100%">
    <MTable :option="tableOption" :data="tableData">
      <template #sex="{ row, $index }">
        <span>有没有第三种性别</span>
      </template>
    </MTable>
  </div>
</template>

操作栏自定义

Show Code
vue
<script lang="ts" setup>
import { ref } from 'vue'
import type { ITableOption } from 'm-eleplus-crud'

const tableOption = ref<ITableOption>({
  border: true,
  menu: true,
  column: [
    {
      label: '名字',
      prop: 'name',
    },
    {
      label: '性别',
      prop: 'sex',
      type: 'select',
      dicData: [
        {
          label: '男',
          value: 1,
        },
        {
          label: '女',
          value: 2,
        },
      ],
    },
  ],
})

const tableData = ref([
  {
    name: 'ZhangSan',
    sex: 1,
  },
  {
    name: 'LiSi',
    sex: 2,
  },
])

const selectData = ref<any>([])
</script>

<template>
  <div style="width: 100%">
    <MTable v-model:select="selectData" :option="tableOption" :data="tableData">
      <template #menu="{ row, $index }">
        <el-link type="primary" :underline="false">自定义</el-link>
      </template>
    </MTable>
  </div>
</template>

Table API

Table Attributes

属性名说明类型默认值
size组件尺寸default | small | large--
loading加载状态booleanfalse
permission权限对象object{}
data表格数据array[]
v-model:select表格选择数据array[]
height表格高度number--
maxHeight表格高度number--
option表格配置ITableOption--

Table 事件

名称说明类型
selectionChange表格选择触发(arr: any[]) => void

Table 插槽

名称说明
prop 值prop 属性的值{row, $index}
menu操作栏插槽{row, $index}

Table Exposes

名称说明类型
clearSelection清空表格选择数据() => void
toggleRowSelection切换某行数据选择状态(index:列表索引,selected:是否选择,type:1 单选/2 多选)(index: number, selected: boolean, type: number) => void
refreshTable刷新表格(重新渲染表格,不是刷新数据)() => void

额外类型

ITableOption

属性名说明类型默认值
menu是否显示操作列booleanfalse
stripe是否显示斑马纹booleanfalse
border是否显示纵向边框booleanfalse
menuWidth操作栏宽度number220
menuFixed操作栏列冻结列 ,true 表示固定在左侧true | 'left' | 'right''right'
menuAlign操作栏按钮的对齐方式'left' | 'center' | 'right''center'
menuTitle操作栏标题名称string'操作'
column配置项ITableColumn[][]

ITableColumn

属性名说明类型默认值
label标题string--
prop字段名string--
dicData数据字典值{label: string, value: any}[][]
dicUrl数据字典接口 url 地址string--
dicQuery数据字典接口请求参数Record<string, any>--
dicHeaders数据字典接口请求头参数Record<string, any>--
dicFormatter数据字典接口返回数据格式化方法(res: any) => { list: any[]; label: string; value: string }--
multipletype=select 时是否多选booleanfalse
imgWidthtype=picture 时图片宽度string'70px'
imgHeighttype=picture 时图片高度string'70px'
imgPrefixtype=picture 时图片 url 前缀string--
imgSuffixtype=picture 时图片 url 字符串间隔string';'
type类型string--

Column Type

名称说明
index索引列
single单选
selection多选
input输入框
number数字输入框
textarea文本域输入框
password密码输入框
year年选择器
month月选择器
date日期选择器
datetime日期时间选择器
week周选择器
datetimerange日期时间范围选择器
daterange日期范围选择器
monthrange月份范围选择器
yearrange年范围选择器
time时间选择器
timerange时间范围选择器
select下拉选择
checkbox多选框
radio单选框
switch切换框
picture图片展示
qrcode二维码展示
barcode一维码展示