Skip to content

Commit 3a4fb02

Browse files
author
Guillaume Chau
committed
docs(demo): dynamic scroller filter example
1 parent e5b5951 commit 3a4fb02

File tree

1 file changed

+38
-5
lines changed

1 file changed

+38
-5
lines changed

docs-src/src/components/DynamicScrollerDemo.vue

Lines changed: 38 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,21 @@
11
<template>
22
<div class="dynamic-scroller-demo">
3+
<div class="toolbar">
4+
<input
5+
v-model="search"
6+
placeholder="Filter..."
7+
>
8+
</div>
9+
310
<DynamicScroller
4-
:items="items"
11+
:items="filteredItems"
512
:min-item-height="54"
613
class="scroller"
714
>
8-
<div slot="before-container" class="notice">
15+
<div
16+
slot="before-container"
17+
class="notice"
18+
>
919
The message heights are unknown.
1020
</div>
1121

@@ -24,16 +34,19 @@
2434
>
2535
<div class="avatar">
2636
<img
27-
:src="item.avatar"
2837
:key="item.avatar"
38+
:src="item.avatar"
2939
alt="avatar"
3040
class="image"
3141
>
3242
</div>
3343
<div class="text">
34-
{{ index }}
3544
{{ item.message }}
3645
</div>
46+
<div class="index">
47+
<span>{{ item.id }} (id)</span>
48+
<span>{{ index }} (index)</span>
49+
</div>
3750
</DynamicScrollerItem>
3851
</template>
3952
</DynamicScroller>
@@ -55,9 +68,19 @@ export default {
5568
data () {
5669
return {
5770
items,
71+
search: '',
5872
}
5973
},
6074
75+
computed: {
76+
filteredItems () {
77+
const { search, items } = this
78+
if (!search) return items
79+
const lowerCaseSearch = search.toLowerCase()
80+
return items.filter(i => i.message.toLowerCase().includes(lowerCaseSearch))
81+
},
82+
},
83+
6184
methods: {
6285
changeMessage (message) {
6386
Object.assign(message, generateMessage())
@@ -87,7 +110,6 @@ export default {
87110
min-height: 32px;
88111
padding: 12px;
89112
box-sizing: border-box;
90-
max-width: 400px;
91113
}
92114
93115
.avatar {
@@ -104,7 +126,18 @@ export default {
104126
border-radius: 50%;
105127
}
106128
129+
.index,
107130
.text {
108131
flex: 1;
109132
}
133+
134+
.text {
135+
max-width: 400px;
136+
}
137+
138+
.index span {
139+
display: inline-block;
140+
width: 160px;
141+
text-align: right;
142+
}
110143
</style>

0 commit comments

Comments
 (0)