Skip to content

Commit b85ac76

Browse files
add custom HTML template support
1 parent f33971d commit b85ac76

File tree

6 files changed

+148
-147
lines changed

6 files changed

+148
-147
lines changed

README.md

Lines changed: 18 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# Overview
2-
vue-loadmore is a two-direction mobile load-more component for vue.js.
2+
vue-loadmore is a two-direction mobile pull-to-refresh component for vue.js.
33

44
# Installation
55
```bash
@@ -36,13 +36,17 @@ Visit [this page](http://leopoldthecoder.github.io/Demos/vue-loadmore/index.html
3636
<li v-for="item in list">{{ item }}</li>
3737
</ul>
3838
</loadmore>
39-
<loadmore :top-method="loadTop2" :bottom-method="loadBottom2" :bottom-all-loaded="allLoaded2" :bottom-need-pull="true">
39+
<loadmore :top-method="loadTop2" :top-status.sync="topStatus">
4040
<ul>
4141
<li v-for="item in list2">{{ item }}</li>
4242
</ul>
43+
<div slot="top" class="kebab-loadmore-top">
44+
<span v-show="topStatus !== 'loading'" :class="{ 'rotate': topStatus === 'drop' }">↓</span>
45+
<span v-show="topStatus === 'loading'">Loading...</span>
46+
</div>
4347
</loadmore>
4448
```
45-
For upward direction, `vue-loadmore` uses pull-to-refresh to load more. Pull the component `topDistance` pixels away from the top and then release it, the function you appointed as `top-method` will run:
49+
For upward direction, pull the component `topDistance` pixels away from the top and then release it, the function you appointed as `top-method` will run:
4650
```Javascript
4751
loadTop() {
4852
...// load more data
@@ -51,22 +55,23 @@ loadTop() {
5155
```
5256
At the end of your `top-method`, don't forget to broadcast the `onTopLoaded` event so that `vue-loadmore` removes `topLoadingText`.
5357

54-
For downward direction, you have two options:
55-
* Set `bottom-need-pull` to `true`, then pull-to-refresh will be applied. In this case, to invoke `bottom-method`, just pull the component `bottomDistance` pixels away from the bottom and then release it.
56-
* Set `bottom-need-pull` to `false` or simply omit it, `bottom-method` will run automatically when the bottom of the component is less than `bottomDistance` pixels away from the bottom of its container.
57-
58-
The [example](http://leopoldthecoder.github.io/Demos/vue-loadmore/index.html) demonstrates the difference between these two options.
59-
58+
For downward direction, things are similar. To invoke `bottom-method`, just pull the component `bottomDistance` pixels away from the bottom and then release it.
6059
```Javascript
61-
loadBottom() {
60+
loadBottom(id) {
6261
...// load more data
6362
this.allLoaded = true;// if all data are loaded
64-
this.$broadcast('onBottomLoaded');
63+
this.$broadcast('onBottomLoaded', id);
6564
}
6665
```
67-
Remember to set `bottom-all-loaded` to `true` after all data are loaded. And of course broadcast `onBottomLoaded`.
66+
Remember to set `bottom-all-loaded` to `true` after all data are loaded. And of course broadcast `onBottomLoaded`. Note that a parameter called `id` is passed to `loadmore`. This is because after the bottom data is loaded, some reposition work is performed inside a `vue-loadmore` instance, and `id` simply tells the component which instance should be repositioned. You don't need to do anything more than passing `id` to `onBottomLoaded` just as shown above.
67+
68+
You can customize the top and bottom DOM using an HTML template. For example, to customize the top DOM, you'll need to add a variable that syncs with `top-status` on `loadmore` tag, and then write your template with a `slot` attribute set to `top` and `class` set to `kebab-loadmore-top`. `top-status` has three possible values that indicates which status the component is at:
69+
* `pull` if the component is being pulled yet not ready to drop
70+
* `drop` if the component is ready to drop
71+
* `loading` if `topMethod` is running
72+
And of course, if a top HTMl template is given, `topPullText`, `topDropText` and `topLoadingText` are all unnecessary.
6873

69-
If you don't need to load data from upward direction, simply omit the `topMethod` attribute. Same goes to downward.
74+
Don't need to load data from upward direction? Simply omit the `topMethod` attribute. Same goes to downward.
7075

7176
# API
7277
| Option | Description | Value | Default |
@@ -82,7 +87,6 @@ If you don't need to load data from upward direction, simply omit the `topMethod
8287
| bottomDistance | distance threshold that triggers `bottomMethod` | Number | 70 |
8388
| bottomMethod | downward load-more function | Function | |
8489
| bottomAllLoaded | if `true`, `bottomMethod` can no longer be triggered | Boolean | false |
85-
| bottomNeedPull | if `true`, pull-to-refresh will be applied on downward direction | Boolean | false |
8690

8791
# License
8892
MIT

cooking.conf.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ cooking.set({
1313
format: 'umd',
1414
moduleName: 'VueLoadmore',
1515

16-
extends: ['vue', 'lint']
16+
extends: ['vue', 'lint', 'saladcss']
1717
});
1818

1919
cooking.add('externals.vue', 'vue');

cooking.example.conf.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ cooking.set({
1111

1212
devServer: false,
1313

14-
extends: ['vue', 'lint']
14+
extends: ['vue', 'lint', 'saladcss']
1515
});
1616

1717
cooking.add('externals.vue', 'vue');

example/index.html

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -47,24 +47,37 @@
4747
height: 300px;
4848
overflow: scroll;
4949
}
50+
51+
.kebab-loadmore-top span {
52+
display: inline-block;
53+
transition: .2s linear;
54+
}
55+
56+
.rotate {
57+
transform: rotate(180deg);
58+
}
5059
</style>
5160
<title>vue-loadmore example</title>
5261
</head>
5362
<body>
54-
<p class="example-title">Bottom loads automatically</p>
63+
<p class="example-title">pull to refresh</p>
5564
<div class="example-wrapper" id="example1">
5665
<loadmore :top-method="loadTop" :bottom-method="loadBottom" :bottom-all-loaded="allLoaded">
5766
<ul class="example-list">
5867
<li v-for="item in list" class="example-listitem">{{ item }}</li>
5968
</ul>
6069
</loadmore>
6170
</div>
62-
<p class="example-title">Bottom pull-to-refresh</p>
71+
<p class="example-title">custom HTML template</p>
6372
<div class="example-wrapper" id="example2">
64-
<loadmore :top-method="loadTop2" :bottom-method="loadBottom2" :bottom-all-loaded="allLoaded2" :bottom-need-pull="true">
73+
<loadmore :top-method="loadTop2" :top-status.sync="topStatus">
6574
<ul class="example-list">
6675
<li v-for="item in list2" class="example-listitem">{{ item }}</li>
6776
</ul>
77+
<div slot="top" class="kebab-loadmore-top">
78+
<span v-show="topStatus !== 'loading'" :class="{ 'rotate': topStatus === 'drop' }"></span>
79+
<span v-show="topStatus === 'loading'">Loading...</span>
80+
</div>
6881
</loadmore>
6982
</div>
7083
<script src="./vue.js"></script>

example/index.js

Lines changed: 3 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ new Vue({
2424
}, 1500);
2525
},
2626

27-
loadBottom() {
27+
loadBottom(id) {
2828
setTimeout(() => {
2929
let lastValue = this.list[this.list.length - 1];
3030
if (lastValue < 40) {
@@ -34,7 +34,7 @@ new Vue({
3434
} else {
3535
this.allLoaded = true;
3636
}
37-
this.$broadcast('onBottomLoaded');
37+
this.$broadcast('onBottomLoaded', id);
3838
}, 1500);
3939
}
4040
},
@@ -55,7 +55,7 @@ new Vue({
5555
data() {
5656
return {
5757
list2: [],
58-
allLoaded2: false
58+
topStatus: ''
5959
};
6060
},
6161

@@ -69,20 +69,6 @@ new Vue({
6969
}
7070
this.$broadcast('onTopLoaded');
7171
}, 1500);
72-
},
73-
74-
loadBottom2() {
75-
setTimeout(() => {
76-
let lastValue = this.list2[this.list2.length - 1];
77-
if (lastValue < 40) {
78-
for (let i = 1; i <= 10; i++) {
79-
this.list2.push(lastValue + i);
80-
}
81-
} else {
82-
this.allLoaded2 = true;
83-
}
84-
this.$broadcast('onBottomLoaded');
85-
}, 1500);
8672
}
8773
},
8874

0 commit comments

Comments
 (0)