Skip to content

Commit 185cfc6

Browse files
committed
Update readme.
1 parent b55bd6d commit 185cfc6

File tree

1 file changed

+70
-75
lines changed

1 file changed

+70
-75
lines changed

README.md

Lines changed: 70 additions & 75 deletions
Original file line numberDiff line numberDiff line change
@@ -22,42 +22,40 @@
2222
</a>
2323
</p>
2424

25+
## Table of contents
26+
2527
* [Advantages](#advantages)
2628
* [Live demos](#live-demos)
2729
* [Performance comparison](#performance-comparison)
2830
* [Build time wasted](#build-time-wasted)
2931
* [Total memory used](#total-memory-used)
3032
* [How it works](#how-it-works)
3133
* [Simple usage](#simple-usage)
34+
* [vfor-mode](#vfor-mode)
35+
* [item-mode](#item-mode)
36+
* [variable height](#variable-height)
3237
* [Attentions](#attentions)
33-
* [Props type](#props-type)
38+
* [**Props type**](#props-type)
3439
* [Public methods](#public-methods)
35-
* [Special scenes](#special-scenes)
36-
* [About variable height](#about-variable-height)
37-
* [About item mode](#about-item-mode)
3840
* [Contributions](#contributions)
3941
* [Changelogs](#changelogs)
4042

4143

4244
## Advantages
4345

46+
* Items are independent.
47+
4448
* Tiny and very easy to use.
4549

4650
* Big data list with high performance.
4751

48-
* Support fixed height and variable height.
49-
50-
* Support set the scroll index or offset to any.
51-
52-
* Event scroll, reach top and bottom can be detected.
53-
5452

5553
## Live demos
5654

57-
* [Build 100,000 items with item-mode](https://tangbc.github.io/vue-virtual-scroll-list/demos/item-mode).
58-
5955
* [Build 100,000 items with vfor-mode](https://tangbc.github.io/vue-virtual-scroll-list/demos/vfor-mode).
6056

57+
* [Build 100,000 items with item-mode](https://tangbc.github.io/vue-virtual-scroll-list/demos/item-mode).
58+
6159
* [Build 100,000 items with variable height](https://tangbc.github.io/vue-virtual-scroll-list/demos/variable-height).
6260

6361
The main difference between `item-mode` and `vfor-mode` is that: `item-mode` make a higher performance but not very convenient to handle changing data frequently; however, `vfor-mode` is just the opposite.
@@ -96,6 +94,10 @@ According to the demos above, here are lists of approximate statistics:
9694
npm install vue-virtual-scroll-list --save
9795
```
9896

97+
### vfor-mode
98+
99+
All you need to care about is only data!
100+
99101
```vue
100102
<template>
101103
<div>
@@ -104,7 +106,6 @@ npm install vue-virtual-scroll-list --save
104106
</virtual-list>
105107
</div>
106108
</template>
107-
108109
<script>
109110
import item from '../item.vue'
110111
import virtualList from 'vue-virtual-scroll-list'
@@ -119,6 +120,62 @@ npm install vue-virtual-scroll-list --save
119120
</script>
120121
```
121122

123+
### item-mode
124+
125+
This mode can save a considerable amount of memory and performance. Props `item`, `itemcount` and `itemprops` are both required, you don't need put `<item/>` with a v-for directive inside `virtual-list`, just assign it as prop `item`:
126+
127+
```vue
128+
<template>
129+
<div>
130+
<virtual-list :size="40" :remain="8"
131+
:item="item"
132+
:itemcount="100000"
133+
:itemprops="getItemprops"
134+
/>
135+
</div>
136+
</template>
137+
<script>
138+
import itemComponent from '../item.vue'
139+
import virtualList from 'vue-virtual-scroll-list'
140+
export default {
141+
data () {
142+
return {
143+
item: itemComponent,
144+
}
145+
},
146+
methods: {
147+
getItemprops (itemIndex) {
148+
const itemProps = getItemProp(itemIndex)
149+
return {
150+
// <item/> will render with itemProps.
151+
// https://vuejs.org/v2/guide/render-function.html#createElement-Arguments
152+
props: itemProps
153+
}
154+
}
155+
},
156+
components: { 'virtual-list': virtualList }
157+
}
158+
</script>
159+
160+
```
161+
162+
Whenever you want to change any item data from list in this mode, you need call public method `forceRender()` after source data change. Increase or decrease items, you need to keep `itemcount` and call `forceRender()` together.
163+
164+
### variable height
165+
166+
Using variable height, props `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 need call public method `updateVariable(index)` to clear the offset cache.
167+
168+
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:
169+
```vue
170+
<template>
171+
<div>
172+
<virtual-list :size="40" :remain="8" :variable="true">
173+
<item v-for="item of items" :key="item.id" :style="{ height: item.height + 'px' }" />
174+
</virtual-list>
175+
</div>
176+
</template>
177+
```
178+
122179
**More use ways or getting start you can refer to these clearly [demos](https://github.com/tangbc/vue-virtual-scroll-list/tree/master/demos) or [test suites](https://github.com/tangbc/vue-virtual-scroll-list/tree/master/test).**
123180

124181

@@ -162,68 +219,6 @@ Here are some usefull public methods you can call via [`ref`](https://vuejs.org/
162219
* `updateVariable(index)`: update item height by index in variable height list.
163220

164221

165-
## Special scenes
166-
167-
### About variable height
168-
169-
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.
170-
171-
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:
172-
```vue
173-
<template>
174-
<div>
175-
<virtual-list :size="40" :remain="8" :variable="true">
176-
<item v-for="item of items" :key="item.id" :style="{ height: item.height + 'px' }" />
177-
</virtual-list>
178-
</div>
179-
</template>
180-
```
181-
182-
Corresponding example you can refer to the [demo of variable height](https://tangbc.github.io/vue-virtual-scroll-list/demos/variable-height).
183-
184-
### About item mode
185-
186-
Using `item-mode` can save a considerable amount of memory and performance. In this mode, prop `item`, `itemcount` and `itemprops` are both required, and you don't have to put `<item/>` with a v-for directive inside `virtual-list`, just assign it as prop `item`:
187-
188-
```vue
189-
<template>
190-
<div>
191-
<virtual-list :size="40" :remain="8"
192-
:item="item"
193-
:itemcount="100000"
194-
:itemprops="getItemprops"
195-
/>
196-
</div>
197-
</template>
198-
199-
<script>
200-
import itemComponent from '../item.vue'
201-
import virtualList from 'vue-virtual-scroll-list'
202-
export default {
203-
data () {
204-
return {
205-
item: itemComponent,
206-
}
207-
},
208-
methods: {
209-
getItemprops (itemIndex) {
210-
const itemProps = getItemProp(itemIndex)
211-
return {
212-
props: itemProps // <item/> will render with itemProps.
213-
}
214-
}
215-
},
216-
components: { 'virtual-list': virtualList }
217-
}
218-
</script>
219-
220-
```
221-
222-
Whenever if you want to change any item data from list in `item-mode`, you just need call public method `forceRender()` after source data change. Increase or decrease items, you need to change `itemcount` and call `forceRender()` together.
223-
224-
Corresponding example you can refer to the [demo of item-mode](https://tangbc.github.io/vue-virtual-scroll-list/demos/item-mode).
225-
226-
227222
## Contributions
228223

229224
Welcome to improve vue-virtual-scroll-list with any issue, pull request or code review.

0 commit comments

Comments
 (0)