comment-list.vue
1.66 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
<template>
<div class="comment-list">
<Scroll :options="scrollOption" @pulling-up="onPullingUp">
<CommentItem
v-for="(comment, index) in commentList"
:key="index"
:parent-comment="comment.parentComment"
:children-comments="comment.childrenComments"
:column-type="columnType">
</CommentItem>
</Scroll>
</div>
</template>
<script>
import CommentItem from './comment-item.vue';
import {Scroll} from 'cube-ui';
import {createNamespacedHelpers} from 'vuex';
import {get} from 'lodash';
const {mapActions} = createNamespacedHelpers('comment');
export default {
name: 'CommentList',
props: {
destId: Number,
columnType: {
type: Number,
default: 1001
}
},
data() {
return {
page: 1,
commentList: [],
scrollOption: {
pullUpLoad: true
}
};
},
mounted() {
this.fetchComments();
},
methods: {
...mapActions(['fetchCommentList']),
async fetchComments() {
const result = await this.fetchCommentList({
destId: this.destId,
columnType: this.columnType,
page: this.page
});
if (result.code === 200) {
this.commentList = this.commentList.concat(get(result, 'data.commentInfos', []));
} else {
this.$createToast && this.$createToast({
txt: result.message || '服务器开小差了',
type: 'warn',
time: 1000
}).show();
}
},
onPullingUp() {
this.page++;
this.fetchComments();
}
},
components: {Scroll, CommentItem}
};
</script>
<style scoped lang="scss">
.comment-list {
width: 100%;
padding: 40px 30px;
}
</style>