Skip to content

Commit cb1e176

Browse files
committed
feat: Change the default value of immediate-check to true and modify README.md
1 parent eb5cb93 commit cb1e176

File tree

8 files changed

+197
-15
lines changed

8 files changed

+197
-15
lines changed

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
# build lib
2+
lib
13
# Logs
24
logs
35
*.log

README.md

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,14 @@
11
# vuejs-loadmore
2-
[![Build Status](https://img.shields.io/github/workflow/status/staticdeng/vuejs-loadmore/Node.js%20CI)](https://github.com/staticdeng/vuejs-loadmore/actions)
2+
[![Npm Version](https://img.shields.io/npm/v/vuejs-loadmore)](https://www.npmjs.com/package/vuejs-loadmore) [![Build Status](https://img.shields.io/github/workflow/status/staticdeng/vuejs-loadmore/Node.js%20CI)](https://github.com/staticdeng/vuejs-loadmore/actions)
3+
4+
[![NPM](https://nodei.co/npm/vuejs-loadmore.png)](https://nodei.co/npm/vuejs-loadmore/)
35

46
A pull-down refresh and pull-up loadmore scroll component for Vue.js.
57

68
Easy to use by providing simple api. Unlike other component libraries, it uses the browser itself to scroll instead of js, so it has a smaller code size but does not lose the user experience.
79

10+
**English** | [中文](./README.zh-CN.md)
11+
812
## Preview
913
[Online demo](https://staticdeng.github.io/vuejs-loadmore/)
1014

@@ -46,7 +50,7 @@ The `on-refresh` and `on-loadmore` will be Emitted when pull refresh or scroll
4650

4751
If you don't need refresh, only not to bind `on-refresh`.
4852

49-
When the data request is completed, the data `finished` needs to be changed to true.
53+
When the data request is finished, the data of `finished` you can changed to true, then will show `finished-text`.
5054

5155
```js
5256
export default {
@@ -58,6 +62,9 @@ export default {
5862
finished: false
5963
};
6064
},
65+
mounted() {
66+
this.fetch();
67+
},
6168
methods: {
6269
onRefresh(done) {
6370
this.list = [];
@@ -137,7 +144,7 @@ export default {
137144
| immediate-check | Whether to check loadmore position immediately after mounted | _boolean_ | `true` |
138145
| load-offset | The `on-loadmore` will be Emitted when the distance from the scroll bar to the bottom is less than the `load-offset` | _number \| string_ | `50` |
139146
| finished | Whether the data is loaded | _boolean_ | `false` |
140-
| error | Whether the data is loaded, the `on-loadmore` will be Emitted only when error text clicked, the `sync` modifier is needed | _boolean_ | `false` |
147+
| error | Whether the data is loaded error, the `on-loadmore` will be Emitted only when error text clicked, the `sync` modifier is needed | _boolean_ | `false` |
141148
| loading-text | The Text when loading in loaded | _string_ | `正在加载` |
142149
| finished-text | The Text when the data is loaded | _string_ | `没有更多了` |
143150
| error-text | The Text when error loaded | _string_ | `请求失败,点击重新加载` |

README.zh-CN.md

Lines changed: 169 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,169 @@
1+
# vuejs-loadmore
2+
[![Npm Version](https://img.shields.io/npm/v/vuejs-loadmore)](https://www.npmjs.com/package/vuejs-loadmore) [![Build Status](https://img.shields.io/github/workflow/status/staticdeng/vuejs-loadmore/Node.js%20CI)](https://github.com/staticdeng/vuejs-loadmore/actions)
3+
4+
[![NPM](https://nodei.co/npm/vuejs-loadmore.png)](https://nodei.co/npm/vuejs-loadmore/)
5+
6+
一个Vue.js 的下拉刷新和上拉加载组件。
7+
8+
通过提供简单的api易于使用。与其他组件库不同,它使用浏览器本身而不是js来滚动容器,因此它的代码量更小,但不损失用户体验。
9+
10+
**中文** | [English](./README.md)
11+
12+
## 预览
13+
[在线demo](https://staticdeng.github.io/vuejs-loadmore/)
14+
15+
也可以扫描以下二维码访问演示:
16+
17+
<img src="https://user-images.githubusercontent.com/20060839/145163261-02025f86-ac87-4016-859f-15677a6d3cf7.png" width="220" height="220" >
18+
19+
## 安装 & 使用
20+
21+
#### 安装 npm 包
22+
23+
```bash
24+
# npm
25+
npm install vuejs-loadmore --save
26+
```
27+
28+
#### 全局导入
29+
30+
```js
31+
import Vue from 'vue';
32+
import VueLoadmore from 'vuejs-loadmore';
33+
34+
Vue.use(VueLoadmore);
35+
```
36+
37+
## 用法
38+
39+
### 基础用法
40+
41+
```html
42+
<vue-loadmore
43+
:on-refresh="onRefresh"
44+
:on-loadmore="onLoad"
45+
:finished="finished">
46+
<div v-for="(item, i) of list" :key="i"></div>
47+
</vue-loadmore>
48+
```
49+
`on-refresh``on-loadmore` 会在下拉刷新或滚动到底部时触发,需要在处理完数据请求后执行回调函数 `done()`
50+
51+
如果你不需要刷新,只需要不绑定`on-refresh`
52+
53+
当数据请求完成后,你可以将`finished`的数据改为true,这样就会显示`没有更多了`
54+
55+
```js
56+
export default {
57+
data() {
58+
return {
59+
list: [],
60+
page: 1,
61+
pageSize: 10,
62+
finished: false
63+
};
64+
},
65+
mounted() {
66+
this.fetch();
67+
},
68+
methods: {
69+
onRefresh(done) {
70+
this.list = [];
71+
this.page = 1;
72+
this.finished = false;
73+
this.fetch();
74+
75+
done();
76+
},
77+
78+
onLoad(done) {
79+
if (this.page <= 10) {
80+
this.fetch();
81+
} else {
82+
// all data loaded
83+
this.finished = true;
84+
}
85+
done();
86+
},
87+
88+
fetch() {
89+
for (let i = 0; i < this.pageSize; i++) {
90+
this.list.push(this.list.length + 1);
91+
}
92+
this.page++;
93+
}
94+
},
95+
}
96+
```
97+
98+
### 错误提示
99+
100+
```html
101+
<vue-loadmore
102+
:on-loadmore="onLoad"
103+
:finished="finished"
104+
:error.sync="error">
105+
<div v-for="(item, i) of list" :key="i"></div>
106+
</vue-loadmore>
107+
```
108+
109+
```js
110+
export default {
111+
data() {
112+
return {
113+
list: [],
114+
finished: false,
115+
error: false,
116+
};
117+
},
118+
methods: {
119+
onLoad() {
120+
fetchSomeThing().catch(() => {
121+
this.error = true;
122+
});
123+
},
124+
},
125+
};
126+
```
127+
128+
## API
129+
130+
### Props
131+
132+
| Attribute | Description | Type | Default |
133+
| --- | --- | --- | --- |
134+
| on-refresh | 顶部下拉触发 | _function_ | - |
135+
| pulling-text | 下拉显示文本 | _string_ | `下拉刷新` |
136+
| loosing-text | 释放显示文本 | _string_ | `释放刷新` |
137+
| loading-text | 正在刷新显示文本 | _string_ | `正在刷新` |
138+
| success-text | 刷新完成显示文本 | _string_ | `刷新完成` |
139+
| show-success-text | 是否显示`success-text` | _boolean_ | `true` |
140+
| pull-distance | 触发正在刷新状态的距离 | _number \| string_ | `50` |
141+
| head-height | 正在刷新显示区域的高度 | _number \| string_ | `50` |
142+
| animation-duration | 下拉刷新动画持续时间 | _number \| string_ | `200` |
143+
| on-loadmore | 滚动到底部触发 | _function_ | - |
144+
| immediate-check | 是否在mounted之后立即检查 | _boolean_ | `true` |
145+
| load-offset | 当滚动条到底部的距离小于 `load-offset` 时,会发出 `on-loadmore` | _number \| string_ | `50` |
146+
| finished | 数据是否加载完毕,改变为true,则会显示`finished-text` | _boolean_ | `false` |
147+
| error | 数据是否加载错误,`on-loadmore`只有在点击错误文本时才会触发,需要`sync`修饰符 | _boolean_ | `false` |
148+
| loading-text | 滚动到底部正在加载显示文本 | _string_ | `正在加载` |
149+
| finished-text | 滚动到底部加载完毕的显示文本 | _string_ | `没有更多了` |
150+
| error-text | 加载错误显示文本 | _string_ | `请求失败,点击重新加载` |
151+
152+
### 方法
153+
154+
使用 ref 获取 List 实例并调用实例方法。
155+
156+
| Name | Description |
157+
| ----- | --------------------- |
158+
| checkScroll | 检查当前的滚动位置,若已滚动至底部,则会触发 `on-loadmore` |
159+
160+
161+
## 例子
162+
163+
查看demo以快速了解如何使用此包。
164+
165+
```bash
166+
git clone [email protected]:staticdeng/vuejs-loadmore.git
167+
yarn install
168+
yarn example:dev
169+
```

example/src/App.vue

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,9 @@ export default {
3737
language: 'Chinese'
3838
};
3939
},
40+
mounted() {
41+
this.fetch();
42+
},
4043
methods: {
4144
initData() {
4245
this.list = [];
@@ -70,7 +73,7 @@ export default {
7073
},
7174
7275
fetch() {
73-
for (let i = 0; i < 10; i++) {
76+
for (let i = 0; i < 15; i++) {
7477
this.list.push(this.list.length + 1);
7578
}
7679
this.page++;

lib/index.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

lib/index.module.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "vuejs-loadmore",
3-
"version": "1.0.1",
3+
"version": "1.0.2",
44
"description": "A pull-down refresh and pull-up loadmore scroll component for Vue.js",
55
"entry": "packages/index.js",
66
"main": "lib/index.js",

packages/vuejs-loadmore/index.vue

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121

2222
<!-- 上拉加载 -->
2323
<div class="vuejs-loadmore">
24-
<div class="vuejs-loadmore-loading" v-if="innerLoading && !finished && !error">
24+
<div class="vuejs-loadmore-loading" v-if="loadLoading && !finished && !error">
2525
<Loading>{{ loadingText }}</Loading>
2626
</div>
2727

@@ -107,7 +107,7 @@ export default {
107107
onLoadmore: Function,
108108
immediateCheck: {
109109
type: Boolean,
110-
default: true
110+
default: false
111111
},
112112
loadOffset: {
113113
type: [Number, String],
@@ -135,7 +135,7 @@ export default {
135135
distance: 0, // 下拉距离
136136
duration: 0, // 动画时间
137137
scroller: null, // 滚动容器元素
138-
innerLoading: false // loadmore loading
138+
loadLoading: false // loadmore loading
139139
};
140140
},
141141
@@ -145,6 +145,7 @@ export default {
145145
// 获取$el最近一个父级可滚动容器元素
146146
this.scroller = getScroller(this.$el);
147147
148+
// 是否立即检查
148149
if (this.immediateCheck) {
149150
this.checkSroll();
150151
}
@@ -166,7 +167,7 @@ export default {
166167
},
167168
168169
watch: {
169-
innerLoading: 'checkSroll',
170+
loadLoading: 'checkSroll',
170171
finished: 'checkSroll'
171172
},
172173
@@ -271,7 +272,7 @@ export default {
271272
272273
checkSroll () {
273274
this.$nextTick(() => {
274-
if (this.innerLoading || !this.onLoadmore || this.finished || this.error) {
275+
if (this.loadLoading || !this.onLoadmore || this.finished || this.error) {
275276
return;
276277
}
277278
@@ -297,20 +298,20 @@ export default {
297298
const isReachEdge = placeholderRect.bottom - scrollerRect.bottom <= loadOffset;
298299
299300
if (isReachEdge) {
300-
this.innerLoading = true;
301+
this.loadLoading = true;
301302
this.timeout(() => this.onLoadmore(this.loadmoreDone), 500);
302303
}
303304
});
304305
},
305306
306307
clickErrorText () {
307308
this.$emit('update:error', false);
308-
this.innerLoading = true;
309+
this.loadLoading = true;
309310
this.timeout(() => this.onLoadmore(this.loadmoreDone), 500);
310311
},
311312
312313
loadmoreDone () {
313-
this.innerLoading = false;
314+
this.loadLoading = false;
314315
}
315316
316317
}

0 commit comments

Comments
 (0)