-
Notifications
You must be signed in to change notification settings - Fork 0
/
Body.vue
111 lines (107 loc) · 2.45 KB
/
Body.vue
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
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
<template>
<el-row>
<el-col :xs="24" :md="24">
<PostList :keyword="keyword" :post-list="postListArray" />
<p v-if="showNores" class="nores">~ 我是有底线滴 ~</p>
<div id="pagination">
<div class="loadmore-default">
<a id="btn-loadmore" href="javascript:void(0);" @click="loadmore">
{{ loadText }}
</a>
</div>
</div>
</el-col>
<!--
<el-col :xs="24" :md="16">
<PostList :keyword="keyword" :post-list="postListArray" />
<p v-if="showNores" class="nores">~ 我是有底线滴 ~</p>
<div id="pagination">
<div class="loadmore-default">
<a id="btn-loadmore" href="javascript:void(0);" @click="loadmore">
{{ loadText }}
</a>
</div>
</div>
</el-col>
<el-col :xs="24" :md="8">
<Aside />
</el-col>
-->
</el-row>
</template>
<script>
import PostList from "./PostList";
export default {
name: "Body",
components: { PostList },
props: {
type: {
type: String,
default: "post"
},
keyword: {
type: String,
default: ""
},
postList: {
type: Array,
default: () => []
}
},
data() {
return {
total: 0,
pageSize: 10,
currentPage: 1,
showNores: false,
loadText: "加载更多",
postListArray: this.postList
};
},
watch: {
postList() {
this.postListArray = this.postList;
}
},
mounted() {
this.loadmore();
},
methods: {
async loadmore() {
this.showNores = false;
this.loadText = "加载中...";
const postsResult = await this.$axios.$post("/blog/post/list", {
postType: this.type,
postStatus: "publish",
search: this.keyword,
pageNum: ++this.currentPage,
pageSize: this.pageSize
});
// console.log(postsResult);
if (postsResult.status === 1) {
this.total = postsResult.data.total;
if (postsResult.data.list.length > 0) {
// 渲染数据
for (const idx in postsResult.data.list) {
const post = postsResult.data.list[idx];
this.postListArray.push(post);
}
this.loadText = "加载更多";
} else {
this.showNores = true;
this.loadText = "加载完成";
}
}
}
}
};
</script>
<style scoped lang="scss">
.nores {
color: #999;
text-align: center;
}
#pagination {
padding: 10px;
}
</style>