-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
185 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
# 基础用法 | ||
|
||
最简单用法只需要准备 `columns` 和 `loadMethod` 即可完成使用。 | ||
|
||
对于数据来源,只需要实现 `loadMethod` 并返回相应数据结构即可,该函数可以返回一个`Promise`作为异步处理。 | ||
|
||
:::demo 从用法不难看出,我们将传统的 `template` 编写套路改为`script options`的形式,让我们专注与逻辑部分,忽略xml结构的臃肿。 | ||
|
||
```html | ||
<template> | ||
<TableData :load-method="loadMethod" :columns="columns" /> | ||
</template> | ||
|
||
<script> | ||
export default { | ||
setup() { | ||
const columns = [ | ||
{ | ||
label: '标题', | ||
prop: 'title', | ||
showOverflowTooltip: true, | ||
}, | ||
{ | ||
label: '描述', | ||
prop: 'brief', | ||
showOverflowTooltip: true, | ||
}, | ||
{ | ||
label: '时间', | ||
prop: 'date', | ||
}, | ||
] | ||
const loadMethod = ({ page }) => { | ||
return new Promise((resolve, reject) => { | ||
// todo 这里可以换成接口数据 | ||
resolve({ | ||
total: 5, | ||
list: [ | ||
{ | ||
title: '标题1', | ||
brief: '描述1', | ||
date: '2021-01-01', | ||
}, | ||
{ | ||
title: '标题2', | ||
brief: '描述2', | ||
date: '2021-01-02', | ||
}, | ||
{ | ||
title: '标题3', | ||
brief: '描述3', | ||
date: '2021-01-03', | ||
}, | ||
{ | ||
title: '标题4', | ||
brief: '描述4', | ||
date: '2021-01-04', | ||
}, | ||
{ | ||
title: '标题5', | ||
brief: '描述5', | ||
date: '2021-01-05', | ||
}, | ||
], | ||
}) | ||
}) | ||
} | ||
return { | ||
columns, | ||
loadMethod, | ||
} | ||
}, | ||
} | ||
</script> | ||
``` | ||
|
||
::: |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
# 格式化 列 | ||
|
||
格式化 column 只需要对在 `column` 中实现了 `formatter` 方法的进行格式化即可。 | ||
|
||
复杂数据或需要 html 渲染可将 formatter 返回 jsx 语法,但需要工程化中配置 `jsx` 支持。 | ||
|
||
:::demo | ||
|
||
```html | ||
<template> | ||
<TableData :load-method="loadMethod" :columns="columns" /> | ||
</template> | ||
|
||
<script> | ||
export default { | ||
setup() { | ||
const columns = [ | ||
{ | ||
label: '标题', | ||
prop: 'title', | ||
showOverflowTooltip: true, | ||
}, | ||
{ | ||
label: '描述', | ||
prop: 'brief', | ||
showOverflowTooltip: true, | ||
}, | ||
{ | ||
label: '时间', | ||
prop: 'date', | ||
// this is a formatter | ||
formatter(row, column, cellValue){ | ||
return <span>我是格式化后的数据{row.date}</span> | ||
}, | ||
}, | ||
] | ||
const loadMethod = ({ page }) => { | ||
return new Promise((resolve, reject) => { | ||
// todo 这里可以换成接口数据 | ||
resolve({ | ||
total: 5, | ||
list: [ | ||
{ | ||
title: '标题1', | ||
brief: '描述1', | ||
date: '2021-01-01', | ||
}, | ||
{ | ||
title: '标题2', | ||
brief: '描述2', | ||
date: '2021-01-02', | ||
}, | ||
{ | ||
title: '标题3', | ||
brief: '描述3', | ||
date: '2021-01-03', | ||
}, | ||
{ | ||
title: '标题4', | ||
brief: '描述4', | ||
date: '2021-01-04', | ||
}, | ||
{ | ||
title: '标题5', | ||
brief: '描述5', | ||
date: '2021-01-05', | ||
}, | ||
], | ||
}) | ||
}) | ||
} | ||
return { | ||
columns, | ||
loadMethod, | ||
} | ||
}, | ||
} | ||
</script> | ||
``` | ||
|
||
::: |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters