topic.vue
1.28 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
<template>
<Article ref="article" title="话题" :on-fetch="onFetch"></Article>
</template>
<script>
import Article from './components/article/article';
import {createNamespacedHelpers} from 'vuex';
const {mapState, mapActions, mapMutations} = createNamespacedHelpers('article');
export default {
name: 'ArticlePage',
data() {
return {
inx: 0,
tag: '',
reload: false
};
},
beforeRouteUpdate(to, from, next) {
if (this.$route.params.tag !== to.params.tag) {
this.$refs.article.init();
this.reload = true;
this.inx = 0;
}
next();
},
methods: {
onFetch() {
console.log('onFetch')
if (!this.allList) {
this.allList = [];
}
const items = Array.from({length: 5}).map((v, i) => {
return {
name: 'chenfeng' + (i + 5 * this.inx),
id: (i + 5 * this.inx)
}
})
this.inx++;
this.allList = this.allList.concat(items);
if (this.reload) {
this.reload = !this.reload;
return Promise.resolve({
data: items,
reload: true
});
}
return Promise.resolve(items);
},
},
components: {
Article
}
};
</script>
<style lang="scss" scoped>
.article-page {
background-color: #f0f0f0;
}
</style>