topic-list.vue
1.75 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
<template>
<Layout class="topic-list-page">
<LayoutHeader slot='header' theme="white" class="topic-list-header">全部话题</LayoutHeader>
<Scroll
class="main-container"
ref="scroll"
:scroll-events="['scroll-end']"
@scroll-end="fetchList">
<div class="topic-list">
<TopicItem v-for="(item, index) in topicList" :key="index" :data="item"></TopicItem>
</div>
<div class="loading">
<p v-if="noMore" class="load-text">没有更多了</p>
<Loading v-else class="load-icon" :size="20"></Loading>
</div>
</Scroll>
</Layout>
</template>
<script>
import {get} from 'lodash';
import {Scroll, Loading} from 'cube-ui';
import TopicItem from './components/topic/list-item';
import {createNamespacedHelpers} from 'vuex';
// import YAS from 'utils/yas-constants';
const {mapState, mapActions} = createNamespacedHelpers('article');
export default {
name: 'TopicListPage',
data() {
return {
data: {},
noMore: false
};
},
created() {
},
activated() {
this.fetchList();
},
async serverPrefetch() {
return this.fetchTopicList({});
},
computed: {
...mapState(['topicList', 'fetchTopicPage'])
},
methods: {
...mapActions(['fetchTopicList']),
fetchList() {
if (this.noMore) {
return;
}
this.fetchTopicList({}).then(res => {
if (+this.fetchTopicPage > +get(res, 'data.totalPage')) {
this.noMore = true;
}
});
}
},
components: {
Scroll,
Loading,
TopicItem
}
};
</script>
<style lang="scss" scoped>
.topic-list {
padding: 10px 0;
}
.loading {
padding-bottom: 20px;
text-align: center;
line-height: 1.2;
}
.load-icon {
display: flex;
justify-content: center;
}
</style>