Skip to content

Commit

Permalink
feat: 更改异步渲染功能为 asyncRender 字段,且默认不开启,值大于0 时开启,详见文档
Browse files Browse the repository at this point in the history
  • Loading branch information
Robin-front committed Sep 29, 2019
1 parent e8bc119 commit 14bfb70
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 11 deletions.
8 changes: 6 additions & 2 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ export default {
| resizable | 是否可拖动调整列宽 | Boolean | false |
| height | 表格高度,单位 px,设置后,如果表格内容大于此值,会固定表头 | Number | - |
| no-data | 数据为空时显示的提示内容 | String | No Data |
| initRowNumber | 异步渲染时,mounted 触发前渲染的行数(建议是刚好首屏) | number | 10 |
| asyncRender | 不为 0 时使用异步渲染模式,mounted 触发前渲染的行数(建议是刚好首屏,**见后文详细说明**) | number | 0 |
| minWidth | 最小列宽 | number | 40 |
| maxWidth | 拖动调整时,可调的最大列宽, 默认不限制 | number | - |
Expand All @@ -144,7 +144,7 @@ export default {
| on-selection-change | 点击全选时触发 | selection:已选项数据; row: 当前选中行数据 |
| on-all-cancel | 全选取消时触发 | selection:已选项数据 |
| on-selection-cancel | 单选取消时触发 | selection:已选项数据 |
| on-render-done | 异步渲染完成时触发 | 无 |
| on-render-done | 异步渲染完成时触发(asyncRender 不为 0 时生效) | - |
| on-scroll-x | 横向滚动事件 | event |
### column
Expand Down Expand Up @@ -172,6 +172,10 @@ export default {
| ------------ | ------- |
| loading | 加载中 |
## asyncRender
**异步渲染功能,适用于数据量特别大,改善首次渲染慢的情况。asyncRender 值为 mounted 之前首次渲染的行数,剩余行数会在 mounted 之后以 RAF 的方式逐行渲染,因些如果设置表格最大高度 height, 可能会造成页面抖动和 reflow, 建议设置 table height prop。 此外, 当表格数据 data 属性变化时,也会造成整表重新渲染,而失去 vue diff 的优势, 可以在首次异步渲染完成后的 on-render-done 事件中,将 asyncRender 的值改为 pageSize 相同的值,这样可以避免整表重新渲染。**
## Test
```bash
yarn test
Expand Down
24 changes: 15 additions & 9 deletions src/table.vue
Original file line number Diff line number Diff line change
Expand Up @@ -203,9 +203,9 @@ export default {
type: String,
default: 'light'
},
initRowNumber: {
asyncRender: {
type: Number,
default: 10,
default: 0,
},
minWidth: {
type: Number,
Expand Down Expand Up @@ -369,14 +369,20 @@ export default {
this._queueId = new Date().getTime();
this.rowHeight = { header: 0, footer: 0 };
this.dataList = [];
this.data.slice(0, this.initRowNumber).forEach((item, index) => {
this.copyItem(item, index)
});
if (this.data.length > this.initRowNumber) {
this.shouldEachRenderQueue = true;
this.eachQueue(this.data, this.initRowNumber, this._queueId);
if (this.asyncRender > 0) {
this.data.slice(0, this.asyncRender).forEach((item, index) => {
this.copyItem(item, index)
});
if (this.data.length > this.asyncRender) {
this.shouldEachRenderQueue = true;
this.eachQueue(this.data, this.asyncRender, this._queueId);
} else {
this.$emit("on-render-done");
}
} else {
this.$emit("on-render-done");
this.data.forEach((item, index) => {
this.copyItem(item, index)
});
}
},
copyItem(item, index) {
Expand Down

0 comments on commit 14bfb70

Please sign in to comment.