Skip to content

Commit ed62a71

Browse files
committed
Update readme.
1 parent bca9092 commit ed62a71

File tree

1 file changed

+21
-29
lines changed

1 file changed

+21
-29
lines changed

README.md

Lines changed: 21 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
* [Props type](#props-type)
2626
* [Public methods](#public-methods)
2727
* [Special scenes](#special-scenes)
28-
* [About variable mode](#about-variable-mode)
28+
* [About variable height](#about-variable-height)
2929
* [About item mode](#about-item-mode)
3030
* [Contributions](#contributions)
3131
* [Changelogs](#changelogs)
@@ -46,11 +46,11 @@
4646

4747
## Live demos
4848

49-
* [Scroll with 100,000 finite data](https://tangbc.github.io/vue-virtual-scroll-list/examples/finite/).
49+
* [Use with item-mode](https://tangbc.github.io/vue-virtual-scroll-list/demos/item-mode).
5050

51-
* [Scroll with request infinite data](https://tangbc.github.io/vue-virtual-scroll-list/examples/infinite/).
51+
* [Use with vfor-mode](https://tangbc.github.io/vue-virtual-scroll-list/demos/vfor-mode).
5252

53-
* [Scroll with variable height mode](https://tangbc.github.io/vue-virtual-scroll-list/examples/variable/).
53+
* [Use with variable height](https://tangbc.github.io/vue-virtual-scroll-list/demos/variable-height).
5454

5555

5656
## How it works
@@ -78,7 +78,6 @@ npm install vue-virtual-scroll-list --save
7878
<script>
7979
import item from '../item.vue'
8080
import virtualList from 'vue-virtual-scroll-list'
81-
8281
export default {
8382
data () {
8483
return {
@@ -96,18 +95,16 @@ npm install vue-virtual-scroll-list --save
9695
```html
9796
<script src="https://unpkg.com/[email protected]/dist/vue.js"></script>
9897
<script src="https://tangbc.github.io/vue-virtual-scroll-list/index.js"></script>
99-
10098
<div id="app">
10199
<virtual-list :size="40" :remain="8" wtag="ul">
102-
<li class="item" v-for="(udf, index) of items" :key="index">Item: # {{ index }}</li>
100+
<li class="item" v-for="(udf, index) of items" :key="index">Item: #{{ index }}</li>
103101
</virtual-list>
104102
</div>
105103
```
106104

107105
```javascript
108106
// Global name as `VirtualScrollList`
109107
Vue.component('virtual-list', VirtualScrollList)
110-
111108
new Vue({
112109
el: '#app',
113110
data: {
@@ -116,6 +113,8 @@ new Vue({
116113
})
117114
```
118115

116+
More use ways or get start you can refer to these clearly [demos](https://github.com/tangbc/vue-virtual-scroll-list/tree/master/demos).
117+
119118

120119
## Attentions
121120

@@ -130,7 +129,7 @@ new Vue({
130129

131130
*Prop* | *Type* | *Required* | *Description* |
132131
:--- | :--- | :--- | :--- |
133-
| size | Number || Each list item height, in variable height mode, this prop just use to calculate the virtual-list outside container viewport height. |
132+
| size | Number || Each list item height, in variable height, this prop just use to calculate the virtual-list outside container viewport fixed height. |
134133
| remain | Number || How many items should be shown in virtual-list viewport, so `size` and `remain` determine the outside container viewport height (`size × remian`). |
135134
| bench | Number | * | Default value is equal to `remain`, unreached items count, not show in virtual-list viewport but exist in real DOM, the larger the bench, the higher the scroll performance will achieved. |
136135
| start | Number | * | Default value is `0`, the initial scroll start index. It must be integer and in the range of list index, if invalid there will be effected as `0` or the last one. |
@@ -142,10 +141,10 @@ new Vue({
142141
| totop | Function | * | Called when virtual-list is scrolled to top, no param. |
143142
| tobottom | Function | * | Called when virtual-list is scrolled to bottom, no param. |
144143
| 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). |
145-
| variable | Function or Boolean | * | For using virtual-list in `variable-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 in `item-mode`. List item vue component, see [details](#about-item-mode) below. |
147-
| itemdata | Array | * | For using virtual-list in `item-mode`. Prop data list or item slots assign to each item, see [details](#about-item-mode) below. |
148-
| itemprop | Function | * | For using virtual-list in `item-mode`. Function call when each item is going to be rendered, see [details](#about-item-mode) below. |
144+
| variable | Function or Boolean | * | Used in variable height, 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+
| item | Component | * | Used in `item-mode`, list item vue component. |
146+
| itemcount | Number | * | Used in `item-mode`, list data total counts. |
147+
| itemprops | Function | * | Used in `item-mode`, a function call when each item is going to be rendered. |
149148

150149

151150
## Public methods
@@ -154,14 +153,14 @@ Here are some usefull public methods you can call via [`ref`](https://vuejs.org/
154153

155154
* `forceRender()`: force render virtual-list if you need or make it refresh.
156155

157-
* `updateVariable(index)`: update item height by index in variable height mode.
156+
* `updateVariable(index)`: update item height by index in variable height list.
158157

159158

160159
## Special scenes
161160

162-
### About variable mode
161+
### About variable height
163162

164-
In `variable-mode`, prop `size` is still required. All the index variable height and scroll offset will be cached by virtual-list after the binary-search calculate, if you want to change anyone `<item/>` height from data, you should call virtual-list's `updateVariable(index)` method to clear the offset cache, refer to [variable example](https://github.com/tangbc/vue-virtual-scroll-list/blob/master/examples/variable/variable.vue#L1) source for detail.
163+
In variable height, prop `remain` and `size` is still required. All the index variable height and scroll offset will be cached by virtual-list after the binary-search calculate, if you want to change anyone `<item/>` height from data, you should call virtual-list public method `updateVariable(index)` to clear the offset cache.
165164

166165
If you assign `variable` as `true`, **do not** set inline style height inside `<item/>` component, you **must** set inline style height on `<item/>` component outside directly, such as:
167166
```vue
@@ -176,40 +175,33 @@ If you assign `variable` as `true`, **do not** set inline style height inside `<
176175

177176
### About item mode
178177

179-
Use `item-mode` can save a considerable amount of memory and performance, stats data check here: [#87](https://github.com/tangbc/vue-virtual-scroll-list/pull/87).
180-
181-
In this mode, prop `item` `itemdata` `itemprop` are both required, and you don't have to put `<item/>` with a v-for frag inside `virtual-list`, just assign it as prop `item`:
178+
Use `item-mode` can save a considerable amount of memory and performance (it's memory occupied is about only 1/10 of `vfor-mode`). In this mode, prop `item`, `itemcount` and `itemprops` are both required, and you don't have to put `<item/>` with a v-for frag inside `virtual-list`, just assign it as prop `item`:
182179

183180
```vue
184181
<template>
185182
<div>
186183
<virtual-list :size="40" :remain="8"
187184
:item="item"
188-
:itemdata="itemdata"
189-
:itemprop="itemprop"
185+
:itemcount="100000"
186+
:itemprops="getItemprops"
190187
/>
191188
</div>
192189
</template>
193190
194191
<script>
195192
import itemComponent from '../item.vue'
196193
import virtualList from 'vue-virtual-scroll-list'
197-
198194
export default {
199195
data () {
200196
return {
201197
item: itemComponent,
202-
itemdata: [ {id: 1}, {id: 2}, {id: 3}, ... ]
203198
}
204199
},
205200
methods: {
206-
// index: item index
207-
// data: item data get from itemdata array
208-
itemprop (index, data) {
209-
const id = { data }
210-
const itemProps = getItemProp(id)
201+
getItemprops (itemIndex) {
202+
const itemProps = getItemProp(itemIndex)
211203
return {
212-
props: itemProps // <item/> will receive prop with itemProps
204+
props: itemProps // <item/> will render with itemProps.
213205
}
214206
}
215207
},

0 commit comments

Comments
 (0)