Skip to content
On this page

table

基本使用

姓名性别年龄
lh19
fxh19
hss19
vue
<template>
  <kn-table :columns="columns" :dataSource="dataSource" />
</template>

<script setup lang="ts">
import { KnTable } from 'knot-vue'
const columns = [
  {
    title: '姓名',
    dataIndex: 'name',
    key: 'name',
    align: 'center',
  },
  {
    title: '性别',
    dataIndex: 'sex',
    key: 'sex',
    align: 'center',
  },
  {
    title: '年龄',
    dataIndex: 'age',
    key: 'age',
    align: 'center',
  },
]

const dataSource = [
  {
    name: 'lh',
    sex: '',
    age: 19,
  },
  {
    name: 'fxh',
    sex: '',
    age: 19,
  },
  {
    sex: '',
    name: 'hss',
    age: 19,
  },
]
</script>

带边框

姓名性别年龄
lh19
fxh19
hss19
vue
<template>
  <kn-table :columns="columns" :dataSource="dataSource" border />
</template>

<script setup lang="ts">
import { KnTable } from 'knot-vue'
const columns = [
  {
    title: '姓名',
    dataIndex: 'name',
    key: 'name',
    align: 'center',
  },
  {
    title: '性别',
    dataIndex: 'sex',
    key: 'sex',
    align: 'center',
  },
  {
    title: '年龄',
    dataIndex: 'age',
    key: 'age',
    align: 'center',
  },
]

const dataSource = [
  {
    name: 'lh',
    sex: '',
    age: 19,
  },
  {
    name: 'fxh',
    sex: '',
    age: 19,
  },
  {
    sex: '',
    name: 'hss',
    age: 19,
  },
]
</script>

插槽

姓名性别年龄
lh
19
fxh
19
hss
19
vue
<template>
  <kn-table :columns="columns" :dataSource="dataSource">
    <template #name="{ row }">
      <div style="color:red">
        {{ row.name }}
      </div>
    </template>
  </kn-table>
</template>

<script setup lang="ts">
import { KnTable } from 'knot-vue'
const columns = [
  {
    title: '姓名',
    dataIndex: 'name',
    key: 'name',
    align: 'center',
  },
  {
    title: '性别',
    dataIndex: 'sex',
    key: 'sex',
    align: 'center',
  },
  {
    title: '年龄',
    dataIndex: 'age',
    key: 'age',
    align: 'center',
  },
]

const dataSource = [
  {
    name: 'lh',
    sex: '',
    age: 19,
  },
  {
    name: 'fxh',
    sex: '',
    age: 19,
  },
  {
    sex: '',
    name: 'hss',
    age: 19,
  },
]
</script>

API

属性名描述类型是否必填默认值
columns表格列名Column[] 见下表true--
dataSource表格数据对应Column的keytrue--

Column

属性名描述类型是否必填默认值
title列名stringtrue--
dataIndex列索引stringtrue--
key列对应字段stringtrue--
align对齐方式stringfalsecenter

API

属性名描述类型是否必填默认值
columns表格列名Column[] 见下表true--
dataSource表格数据对应Column的keytrue--

Released under the MIT License.