Skip to content

Commit 5dc430f

Browse files
committed
update example
1 parent 8abb4a5 commit 5dc430f

File tree

5 files changed

+1223
-46
lines changed

5 files changed

+1223
-46
lines changed

example/App.vue renamed to example/Demo.vue

Lines changed: 8 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
11
<template>
22
<div id="app">
3-
<github></github>
43
<h1>vue-mugen-scroll</h1>
54
<h2>Infinite scroll component for Vue.js</h2>
6-
<div class="wrap" ref="scrollContainer">
5+
<div class="wrap" :class="{'can-scroll': scrollableContainer}" ref="scrollContainer">
76
<div class="users" v-if="users.length > 0">
87
<div class="user" v-for="user in users">
98
<img class="avatar" :src="user.avatar_url" height="40" alt="">
@@ -14,7 +13,7 @@
1413
class="you-can-add-custom-class-name"
1514
:handler="fetchUsers"
1615
:should-handle="!loading"
17-
scroll-container="scrollContainer">
16+
:scroll-container="scrollableContainer && 'scrollContainer'">
1817
loading <span class="loading dots"></span>
1918
</mugen-scroll>
2019
</div>
@@ -27,10 +26,10 @@
2726
import http from 'axios'
2827
2928
import MugenScroll from '../src'
30-
import Github from './Github.vue'
3129
3230
export default {
33-
name: 'app',
31+
name: 'demo',
32+
props: ['scrollableContainer'],
3433
data() {
3534
return {
3635
users: [], count: 0, loading: false
@@ -50,24 +49,13 @@
5049
}
5150
},
5251
components: {
53-
MugenScroll,
54-
Github
52+
MugenScroll
5553
}
5654
}
5755
</script>
5856

5957
<style src="text-spinners/spinners.css"></style>
6058
<style>
61-
body {
62-
margin: 0;
63-
text-align: center;
64-
font-family: -apple-system, BlinkMacSystemFont,
65-
'avenir next', avenir,
66-
helvetica, 'helvetica neue',
67-
Ubuntu,
68-
'segoe ui', arial,
69-
sans-serif;
70-
}
7159
.users {
7260
background-color: #f0f0f0;
7361
.user {
@@ -86,15 +74,14 @@
8674
background-color: #f0f0f0;
8775
}
8876
.count {
89-
position: fixed;
90-
bottom: 10px;
91-
right: 10px;
9277
font-size: 18px;
78+
margin-top: 10px;
9379
}
9480
.wrap {
9581
max-width: 400px;
82+
}
83+
.wrap.can-scroll {
9684
height: 300px;
97-
margin: 0 auto;
9885
overflow-y: auto;
9986
}
10087
</style>

example/Github.vue

Lines changed: 0 additions & 7 deletions
This file was deleted.

example/index.js

Lines changed: 66 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,68 @@
1-
import Vue from 'vue'
2-
import App from './App'
1+
import Aimer from 'aimer'
2+
import 'aimer/dist/aimer.css'
33

4-
new Vue({
5-
el: '#app',
6-
render: h => h(App)
4+
import Demo from './Demo.vue'
5+
6+
const aimer = new Aimer({
7+
title: 'vue-mugen-scroll',
8+
twitter: '_egoistlily',
9+
github: 'egoist/vue-mugen-scroll'
10+
})
11+
12+
aimer.add({
13+
title: 'Default',
14+
component: Demo,
15+
example: `<template>
16+
<div id="app">
17+
<div class="list">your list of items</div>
18+
<!-- add the component right after your list -->
19+
<mugen-scroll :handler="fetchData" :should-handle="!loading">
20+
loading...
21+
</mugen-scroll>
22+
</div>
23+
</template>
24+
25+
<script>
26+
import MugenScroll from 'vue-mugen-scroll'
27+
28+
export default {
29+
data() {
30+
// do not run handler when it's loading
31+
return {loading: false}
32+
},
33+
methods: {
34+
fetchData() {
35+
this.loading = true
36+
// ... the code you wanna run to fetch data
37+
this.loading = false
38+
}
39+
},
40+
components: {MugenScroll}
41+
}
42+
</script>`.trim()
43+
})
44+
45+
aimer.add({
46+
title: 'Scrollable container',
47+
component: {
48+
render() {
49+
return <Demo scrollableContainer={true} />
50+
}
51+
},
52+
example: `<template>
53+
<div class="wrap"
54+
<!-- the container is scrollable here -->
55+
style="height: 200px; overflow: auto;"
56+
<!-- add the ref -->
57+
ref="wrap">
58+
<div class="list"><!-- your list --></div>
59+
<mugen-scroll
60+
<!-- pass the ref id -->
61+
scroll-container="wrap">
62+
Loading...
63+
</mugen-scroll>
64+
</div>
65+
</template>`.trim()
766
})
67+
68+
aimer.start('#app')

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@
3333
"component"
3434
],
3535
"devDependencies": {
36+
"aimer": "^2.0.8",
3637
"axios": "^0.16.1",
3738
"bili": "^0.15.3",
3839
"eslint-config-rem": "^3.1.0",

0 commit comments

Comments
 (0)