Skip to content

Commit 39f86ff

Browse files
committed
Update reade me
1 parent b1b72fe commit 39f86ff

File tree

2 files changed

+71
-8
lines changed

2 files changed

+71
-8
lines changed

README.md

Lines changed: 65 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,10 @@
2323
* [Using by script include](#using-by-script-include)
2424
* [Attentions](#attentions)
2525
* [Props type](#props-type)
26+
* [Public methods](#public-methods)
2627
* [Special scenes](#special-scenes)
2728
* [About variable height](#about-variable-height)
29+
* [About item mode](#about-item-mode)
2830
* [Contributions](#contributions)
2931
* [Changelogs](#changelogs)
3032

@@ -60,7 +62,7 @@
6062

6163
#### Using by npm module:
6264

63-
```
65+
```console
6466
npm install vue-virtual-scroll-list --save
6567
```
6668

@@ -140,7 +142,19 @@ new Vue({
140142
| totop | Function | * | Called when virtual-list is scrolled to top, no param. |
141143
| tobottom | Function | * | Called when virtual-list is scrolled to bottom, no param. |
142144
| onscroll | Function | * | Called when virtual-list is scrolling, with param: [`(event, data)`](https://github.com/tangbc/vue-virtual-scroll-list/releases/tag/v1.1.7). |
143-
| variable | Function or Boolean | * | For using virtual-list with variable height mode. If assign `Function`, this prop is a variable height getter function which is called with param: `(index)` when each item is ready to be calculated. If assign `Boolean`, virtual-list will get each item variable height by it's inline style height automatic. |
145+
| variable | Function or Boolean | * | For using virtual-list with `variable height mode`. If assign `Function`, this prop is a variable height getter function which is called with param: `(index)` when each item is ready to be calculated. If assign `Boolean`, virtual-list will get each item variable height by it's inline style height automatic. |
146+
| item | Component | * | For using virtual-list with `item mode` see [details](#about-item-mode) below. |
147+
| itemdata | Array | * | For using virtual-list with `item mode` see [details](#about-item-mode) below |
148+
| itemprop | Function | * | For using virtual-list with `item mode` see [details](#about-item-mode) below. |
149+
150+
151+
## Public methods
152+
153+
Here are some usefull public methods if you can call via [`ref`](https://vuejs.org/v2/guide/components-edge-cases.html#Accessing-Child-Component-Instances-amp-Child-Elements):
154+
155+
* `forceRender()`: force render virtual-list if you need or make it refresh.
156+
157+
* `updateVariable(index)`: update variable by index in variable height mode.
144158

145159

146160
## Special scenes
@@ -160,6 +174,55 @@ If you are using `variable` assign by `Boolean`, **do not** set inline style hei
160174
</template>
161175
```
162176

177+
### About item mode
178+
179+
Use item mode can save a considerable amount of memory, stats can see [#87](https://github.com/tangbc/vue-virtual-scroll-list/pull/87).
180+
181+
In this mode prop `item`, `itemdata` and `itemprop` is both required, you don't need put `<item/>` inside `virtual-list` just assign it as prop `item`:
182+
183+
* `item`: The list vue item component.
184+
185+
* `itemdata`: The prop data list assign to each item.
186+
187+
* `itemprop`: Call when each item is going to be rendered.
188+
189+
```vue
190+
<template>
191+
<div>
192+
<virtual-list :size="40" :remain="8"
193+
:item="item"
194+
:itemdata="itemdata"
195+
:itemprop="itemprop"
196+
/>
197+
</div>
198+
</template>
199+
200+
<script>
201+
import itemComponent from '../item.vue'
202+
import virtualList from 'vue-virtual-scroll-list'
203+
204+
export default {
205+
data () {
206+
return {
207+
item: itemComponent,
208+
itemdata: [ {id: 1}, {id: 2}, {id: 3}, ... ]
209+
}
210+
},
211+
methods: {
212+
itemprop (index, data) {
213+
return {
214+
props: {
215+
data
216+
}
217+
}
218+
}
219+
},
220+
components: { 'virtual-list': virtualList }
221+
}
222+
</script>
223+
224+
```
225+
163226

164227
## Contributions
165228

index.js

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@
4949
totop: Function,
5050
tobottom: Function,
5151
onscroll: Function,
52-
items: { type: Array },
52+
itemdata: { type: Array },
5353
item: { type: Object },
5454
itemprop: { type: Function }
5555
},
@@ -147,7 +147,7 @@
147147
}
148148
},
149149

150-
// force render ui list if we needed.
150+
// public method, force render ui list if we needed.
151151
// call this before the next repaint to get better performance.
152152
forceRender: function () {
153153
var that = this
@@ -273,7 +273,7 @@
273273
}
274274
},
275275

276-
// the ONLY ONE public method, allow the parent update variable by index.
276+
// public method, allow the parent update variable by index.
277277
updateVariable: function (index) {
278278
// clear/update all the offfsets and heights ahead of index.
279279
this.getVarOffset(index, true)
@@ -326,10 +326,10 @@
326326

327327
// item mode shoud judge from items prop.
328328
if (this.item) {
329-
if (!this.items.length) {
329+
if (!this.itemdata.length) {
330330
delta.start = 0
331331
}
332-
delta.total = this.items.length
332+
delta.total = this.itemdata.length
333333
} else {
334334
if (!slots) {
335335
slots = []
@@ -369,7 +369,7 @@
369369
var targets = []
370370
for (var i = delta.start; i <= Math.ceil(delta.end); i++) {
371371
// create vnode, using custom attrs binder.
372-
var slot = this.item ? this.$createElement(this.item, this.itemprop(i, this.items[i])) : slots[i]
372+
var slot = this.item ? this.$createElement(this.item, this.itemprop(i, this.itemdata[i])) : slots[i]
373373
targets.push(slot)
374374
}
375375

0 commit comments

Comments
 (0)