layui/example/docs/zh-CN/components/table.md

334 lines
6.9 KiB
Markdown
Raw Normal View History

::: anchor
:::
2021-10-26 01:13:23 +08:00
::: title 基础使用
2021-10-26 01:14:17 +08:00
:::
2021-10-09 10:41:52 +08:00
::: demo
<template>
2021-10-10 05:48:45 +08:00
<lay-table :columns="columns" :dataSource="dataSource">
<template v-slot:username="{ data }"> {{data.username}} </template>
<template v-slot:password="{ data }"> {{data.password}} </template>
<template v-slot:operator="{ data }">
<lay-button >修改</lay-button>
<lay-button type="primary">删除</lay-button>
</template>
2021-10-10 05:48:45 +08:00
</lay-table>
2021-10-09 10:41:52 +08:00
</template>
<script>
import { ref } from 'vue'
export default {
setup() {
2021-10-10 05:48:45 +08:00
const columns = [
{
title:"账户",
width:"200px",
slot:"username",
key:"username"
},{
title:"密码",
width: "180px",
slot:"password",
key:"password"
},{
title:"年龄",
width: "180px",
key:"age"
},{
title:"操作",
2021-10-10 05:48:45 +08:00
width: "180px",
customSlot:"operator",
key:"operator"
2021-10-10 05:48:45 +08:00
}
]
const dataSource = [
{username:"root", password:"root", age:"18"},
{username:"woow", password:"woow", age:"20"}
]
2021-10-09 10:41:52 +08:00
return {
2021-10-10 05:48:45 +08:00
columns,
dataSource
2021-10-09 10:41:52 +08:00
}
}
}
</script>
:::
2021-10-26 01:13:23 +08:00
::: title 不同尺寸
2021-10-26 01:14:17 +08:00
:::
::: demo
<template>
<lay-table :columns="columns" :dataSource="dataSource" size="lg">
<template v-slot:username="{ data }"> {{data.username}} </template>
<template v-slot:password="{ data }"> {{data.password}} </template>
<template v-slot:operator="{ data }">
<lay-button >修改</lay-button>
<lay-button type="primary">删除</lay-button>
</template>
</lay-table>
</template>
<script>
import { ref } from 'vue'
export default {
setup() {
const columns = [
{
title:"账户",
width:"200px",
slot:"username",
key:"username"
},{
title:"密码",
width: "180px",
slot:"password",
key:"password"
},{
title:"年龄",
width: "180px",
key:"age"
},{
title:"操作",
width: "180px",
customSlot:"operator",
key:"operator"
}
]
const dataSource = [
{username:"root", password:"root", age:"18"},
{username:"woow", password:"woow", age:"20"}
]
return {
columns,
dataSource
}
}
}
</script>
:::
2021-10-26 01:13:23 +08:00
::: title 开启分页
2021-10-26 01:14:17 +08:00
:::
::: demo
<template>
<lay-table :columns="columns" :dataSource="dataSource" :page="page" @change="change">
<template v-slot:username="{ data }"> {{data.username}} </template>
<template v-slot:password="{ data }"> {{data.password}} </template>
<template v-slot:operator="{ data }">
<lay-button >修改</lay-button>
<lay-button type="primary">删除</lay-button>
</template>
</lay-table>
</template>
<script>
import { ref } from 'vue'
export default {
setup() {
const page = {
total: 100,
limit: 10
}
const change = function({ current }){
console.log("当前页:" + JSON.stringify(current))
}
const columns = [
{
title:"账户",
width:"200px",
slot:"username",
key:"username"
},{
title:"密码",
width: "180px",
slot:"password",
key:"password"
},{
title:"年龄",
width: "180px",
key:"age"
},{
title:"操作",
width: "180px",
customSlot:"operator",
key:"operator"
}
]
const dataSource = [
{username:"root", password:"root", age:"18"},
{username:"woow", password:"woow", age:"20"}
]
return {
page,
change,
columns,
dataSource
}
}
}
</script>
:::
2021-10-26 01:13:23 +08:00
::: title 完整表格
2021-10-26 01:14:17 +08:00
:::
::: demo
<template>
2021-11-07 15:55:08 +08:00
<lay-table :columns="columns" id="id" :dataSource="dataSource" v-model:selectedKeys="selectedKeys" :checkbox="checkbox" :default-toolbar="defaultToolbar" @row="rowClick">
<template v-slot:toolbar>
2021-10-15 09:46:45 +08:00
<lay-button size="sm">新增</lay-button>
<lay-button size="sm">删除</lay-button>
</template>
<template v-slot:username="{ data }"> {{data.username}} </template>
<template v-slot:password="{ data }"> {{data.password}} </template>
<template v-slot:operator="{ data }">
<lay-button >修改</lay-button>
<lay-button type="primary">删除</lay-button>
</template>
</lay-table>
</template>
<script>
import { ref } from 'vue'
export default {
setup() {
const selectedKeys = ref(['1'])
2021-10-15 14:27:58 +08:00
const checkbox = ref(true)
const defaultToolbar = ref(true)
const columns = [
{
title:"账户",
width:"200px",
2021-12-15 00:57:30 +08:00
customSlot:"username",
key:"username"
},{
title:"密码",
width: "180px",
2021-12-15 00:57:30 +08:00
customSlot:"password",
key:"password"
},{
title:"年龄",
width: "180px",
key:"age"
},{
title:"操作",
width: "180px",
customSlot:"operator",
key:"operator"
}
]
const dataSource = [
{id:"1", username:"root", password:"root", age:"18"},
{id:"2", username:"woow", password:"woow", age:"20"}
]
const rowClick = function(data) {
2021-12-15 00:57:30 +08:00
console.log(JSON.stringify(data))
}
const rowDoubleClick = function(data) {
2021-12-15 00:57:30 +08:00
console.log(JSON.stringify(data))
}
return {
columns,
dataSource,
2021-10-15 14:27:58 +08:00
selectedKeys,
checkbox,
defaultToolbar,
rowClick,
rowDoubleClick
}
}
}
</script>
:::
2021-12-25 22:23:40 +08:00
::: title Table 属性
2021-10-13 10:19:38 +08:00
:::
2021-10-12 18:00:09 +08:00
2021-11-07 15:55:08 +08:00
::: table
2021-12-26 03:19:52 +08:00
| 属性 | 描述 | 类型 | 默认值 | 可选值 |
| -------------------- | ----------------------------- | ---- | ------ | -------------- |
| columns | 列配置 - [更多](#tableColumn) | -- | -- | -- |
| dataSource | 数据源 | -- | -- | -- |
| checkbox | 开启复选框 | -- | -- | -- |
| id | 主键 | -- | -- | -- |
| v-model:selectedKeys | 选中项 | -- | -- | -- |
| default-toolbar | 工具栏 | -- | -- | -- |
| size | 尺寸 | -- | -- | `lg` `md` `sm` |
2021-10-15 09:46:45 +08:00
2021-11-07 15:55:08 +08:00
:::
2021-12-25 22:23:40 +08:00
::: title Table 事件
:::
2021-11-07 15:55:08 +08:00
::: table
2021-11-05 01:26:20 +08:00
| 属性 | 描述 | 参数 |
| ---------- | ------ | ------------- |
| row | 行单击 | data : 当前行 |
| row-double | 行双击 | data : 当前行 |
2021-11-07 15:55:08 +08:00
:::
2021-10-15 09:46:45 +08:00
2021-12-25 22:23:40 +08:00
::: title Table 插槽
2021-10-15 09:46:45 +08:00
:::
2021-11-07 15:55:08 +08:00
::: table
2021-12-25 22:23:40 +08:00
| 插槽 | 描述 | 参数 |
2021-11-05 01:26:20 +08:00
| ------- | ------------ | ---- |
| toolbar | 自定义工具栏 | -- |
2021-11-07 15:55:08 +08:00
2021-11-07 15:56:24 +08:00
:::
2021-12-15 00:57:30 +08:00
2021-12-26 03:19:52 +08:00
### <div id="tableColumn"></div>
2021-12-25 22:23:40 +08:00
::: title Table Column 属性
2021-12-15 00:57:30 +08:00
:::
::: table
2021-12-26 03:19:52 +08:00
| 插槽 | 描述 | 默认 |
| ---------- | ---------- | ---- |
| title | 列标题 | -- |
| key | 数据字段 | -- |
2021-12-25 22:23:40 +08:00
| customSlot | 自定义插槽 | -- |
2021-12-26 03:19:52 +08:00
| width | 宽度 | -- |
2021-12-25 22:23:40 +08:00
2021-12-16 17:57:59 +08:00
:::
::: comment
2021-12-25 22:23:40 +08:00
:::