Skip to content

Commit a1d02aa

Browse files
committed
docs: add en and zh top direction guide page
1 parent 0ac1643 commit a1d02aa

File tree

3 files changed

+112
-0
lines changed

3 files changed

+112
-0
lines changed

docs/.vuepress/config.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ module.exports = {
4343
'',
4444
'start-with-hn',
4545
'use-with-filter-or-tabs',
46+
'top-dir-scroll',
4647
'configure-load-msg',
4748
'configure-plugin-opts',
4849
],
@@ -86,6 +87,7 @@ module.exports = {
8687
'',
8788
'start-with-hn',
8889
'use-with-filter-or-tabs',
90+
'top-dir-scroll',
8991
'configure-load-msg',
9092
'configure-plugin-opts',
9193
],

docs/guide/top-dir-scroll.md

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
---
2+
previewLink: //jsfiddle.net/PeachScript/qac2h5v1/embedded/result/
3+
---
4+
5+
# Top Direction Scroll
6+
7+
Okay, it's the time to try the top direction scroll list, this plugin will save and restore scroll height automatically since `v2.4.0`, it means top direction feature can be used out of the box now!
8+
9+
``` html {5}
10+
<header>
11+
<!-- Hacker News header -->
12+
</header>
13+
14+
<infinite-loading direction="top" @infinite="infiniteHandler"></infinite-loading>
15+
16+
<div v-for="(item, $index) in list" :key="$index">
17+
<!-- Hacker News item loop -->
18+
</div>
19+
```
20+
21+
In the template, we moved the `InfiniteLoading` component to the top of the news list, and set `direction` property to `top`.
22+
23+
``` js {21}
24+
import axios from 'axios';
25+
26+
const api = '//hn.algolia.com/api/v1/search_by_date?tags=story';
27+
28+
export default {
29+
data() {
30+
return {
31+
page: 1,
32+
list: [],
33+
};
34+
},
35+
methods: {
36+
infiniteHandler($state) {
37+
axios.get(api, {
38+
params: {
39+
page: this.page,
40+
},
41+
}).then(({ data }) => {
42+
if (data.hits.length) {
43+
this.page += 1;
44+
this.list.unshift(...data.hits.reverse());
45+
$state.loaded();
46+
} else {
47+
$state.complete();
48+
}
49+
});
50+
},
51+
},
52+
};
53+
```
54+
55+
The script part is almost the same as the [basic Hacker News](./start-with-hn.md), the difference is, we reverse the news data from server and unshift them into the `list`. That's it, this plugin will do the remaining work, is it very easy?

docs/zh/guide/top-dir-scroll.md

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
---
2+
previewLink: //jsfiddle.net/PeachScript/qac2h5v1/embedded/result/
3+
---
4+
5+
# 向上进行无限滚动
6+
7+
现在是时候尝试完成一个方向朝上的无限滚动列表了,从 `v2.4.0` 版本开始,此插件将会自动保存和复原滚动条的高度,这意味着向上无限滚动的功能现在可以开箱即用!
8+
9+
``` html {5}
10+
<header>
11+
<!-- Hacker News header -->
12+
</header>
13+
14+
<infinite-loading direction="top" @infinite="infiniteHandler"></infinite-loading>
15+
16+
<div v-for="(item, $index) in list" :key="$index">
17+
<!-- Hacker News item loop -->
18+
</div>
19+
```
20+
21+
在模板中,我们将 `InfiniteLoading` 组件移动到了新闻列表的上方,并且设置 `direction` 属性值为 `top`
22+
23+
``` js {21}
24+
import axios from 'axios';
25+
26+
const api = '//hn.algolia.com/api/v1/search_by_date?tags=story';
27+
28+
export default {
29+
data() {
30+
return {
31+
page: 1,
32+
list: [],
33+
};
34+
},
35+
methods: {
36+
infiniteHandler($state) {
37+
axios.get(api, {
38+
params: {
39+
page: this.page,
40+
},
41+
}).then(({ data }) => {
42+
if (data.hits.length) {
43+
this.page += 1;
44+
this.list.unshift(...data.hits.reverse());
45+
$state.loaded();
46+
} else {
47+
$state.complete();
48+
}
49+
});
50+
},
51+
},
52+
};
53+
```
54+
55+
逻辑部分跟 [基础 Hacker News](./start-with-hn.md) 几乎一致,不同的地方在于,我们将拿到的新闻数据进行了反转然后插入到了列表的最前面。这样就可以了,剩下的事插件将会替我们完成,是不是很简单?

0 commit comments

Comments
 (0)