Skip to content

Commit 8b665c4

Browse files
author
Guillaume Chau
committed
feat(demo): test chat
1 parent dece681 commit 8b665c4

File tree

3 files changed

+101
-0
lines changed

3 files changed

+101
-0
lines changed

docs-src/src/App.vue

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
<router-link :to="{ name: 'home' }" exact>Home</router-link>
99
<router-link :to="{ name: 'recycle' }">Recycle scroller demo</router-link>
1010
<router-link :to="{ name: 'dynamic' }">Dynamic scroller demo</router-link>
11+
<router-link :to="{ name: 'test-chat' }">Chat demo</router-link>
1112
</nav>
1213
<router-view class="page"/>
1314
</div>

docs-src/src/components/TestChat.vue

Lines changed: 98 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,98 @@
1+
<template>
2+
<div class="hello">
3+
<div>
4+
<button @click="addItems()">
5+
Add item
6+
</button>
7+
<button @click="addItems(5)">
8+
Add 5 items
9+
</button>
10+
<button @click="addItems(10)">
11+
Add 10 items
12+
</button>
13+
</div>
14+
15+
<DynamicScroller
16+
ref="scroller"
17+
:items="items"
18+
:min-item-height="24"
19+
class="scroller"
20+
@resize="scrollToBottom()"
21+
>
22+
<DynamicScrollerItem
23+
slot-scope="{ item, index, active }"
24+
:item="item"
25+
:active="active"
26+
:data-index="index"
27+
>
28+
<div
29+
class="message"
30+
:style="{
31+
height: `${item.size}px`,
32+
}"
33+
>
34+
{{ item.text }}
35+
</div>
36+
</DynamicScrollerItem>
37+
</DynamicScroller>
38+
</div>
39+
</template>
40+
41+
<script>
42+
import faker from 'faker'
43+
44+
export default {
45+
name: 'TestChat',
46+
47+
data () {
48+
return {
49+
items: [],
50+
}
51+
},
52+
53+
methods: {
54+
addItems (count = 1) {
55+
for (let i = 0; i < count; i++) {
56+
this.items.push({
57+
text: faker.lorem.sentence(),
58+
id: this.items.length + 1,
59+
size: Math.random() * 120 + 40,
60+
})
61+
}
62+
this.scrollToBottom()
63+
},
64+
65+
scrollToBottom () {
66+
this.$refs.scroller.scrollToBottom()
67+
},
68+
},
69+
}
70+
</script>
71+
72+
<style scoped>
73+
h1,
74+
h2 {
75+
font-weight: normal;
76+
}
77+
ul {
78+
list-style-type: none;
79+
padding: 0;
80+
}
81+
li {
82+
display: inline-block;
83+
margin: 0 10px;
84+
}
85+
a {
86+
color: #42b983;
87+
}
88+
89+
.scroller {
90+
height: 500px;
91+
border: 2px solid #ddd;
92+
}
93+
94+
.message {
95+
padding: 10px 10px 9px;
96+
border-bottom: solid 1px #eee;
97+
}
98+
</style>

docs-src/src/router.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import VueRouter from 'vue-router'
44
import Home from './components/Home.vue'
55
import Recycle from './components/RecycleScrollerDemo.vue'
66
import Dynamic from './components/DynamicScrollerDemo.vue'
7+
import TestChat from './components/TestChat.vue'
78

89
Vue.use(VueRouter)
910

@@ -12,5 +13,6 @@ export default new VueRouter({
1213
{ path: '/', name: 'home', component: Home },
1314
{ path: '/recycle', name: 'recycle', component: Recycle },
1415
{ path: '/dynamic', name: 'dynamic', component: Dynamic },
16+
{ path: '/test-chat', name: 'test-chat', component: TestChat },
1517
],
1618
})

0 commit comments

Comments
 (0)