|
@@ -1,45 +1,67 @@
|
|
<script setup lang="ts">
|
|
<script setup lang="ts">
|
|
-import type { PostSketch } from '@/models';
|
|
|
|
-import { onMounted, ref } from 'vue';
|
|
|
|
-import { api } from '@/utils/axios';
|
|
|
|
-import PostCard from '@/components/PostCard.vue';
|
|
|
|
|
|
+import type { PostSketch } from '@/models'
|
|
|
|
+import { onMounted, ref } from 'vue'
|
|
|
|
+import { api } from '@/utils/axios'
|
|
|
|
+import PostCard from '@/components/PostCard.vue'
|
|
|
|
|
|
-const data = ref<PostSketch[]>([]);
|
|
|
|
-const pageSize = 10;
|
|
|
|
-const isEnd = ref(false);
|
|
|
|
|
|
+const data = ref<PostSketch[]>([])
|
|
|
|
+const pageSize = 10
|
|
|
|
+const isEnd = ref(false)
|
|
|
|
|
|
function nextDatum() {
|
|
function nextDatum() {
|
|
if (isEnd.value) {
|
|
if (isEnd.value) {
|
|
- return;
|
|
|
|
|
|
+ return
|
|
}
|
|
}
|
|
- api.postList(pageSize, data.value.length).then((res) => {
|
|
|
|
- if (res.data.length < pageSize) {
|
|
|
|
- isEnd.value = true;
|
|
|
|
- }
|
|
|
|
- data.value = [...data.value, ...res.data];
|
|
|
|
- }).catch((err) => {
|
|
|
|
- console.error(err);
|
|
|
|
- });
|
|
|
|
|
|
+ api
|
|
|
|
+ .postList(pageSize, data.value.length)
|
|
|
|
+ .then((res) => {
|
|
|
|
+ if (res.data.length < pageSize) {
|
|
|
|
+ isEnd.value = true
|
|
|
|
+ }
|
|
|
|
+ data.value = [...data.value, ...res.data]
|
|
|
|
+ })
|
|
|
|
+ .catch((err) => {
|
|
|
|
+ console.error(err)
|
|
|
|
+ })
|
|
}
|
|
}
|
|
|
|
|
|
onMounted(() => {
|
|
onMounted(() => {
|
|
- nextDatum();
|
|
|
|
-});
|
|
|
|
-
|
|
|
|
|
|
+ nextDatum()
|
|
|
|
+})
|
|
</script>
|
|
</script>
|
|
|
|
|
|
<template>
|
|
<template>
|
|
<div>
|
|
<div>
|
|
<PostCard v-for="item of data" :key="item.id" :target="item" />
|
|
<PostCard v-for="item of data" :key="item.id" :target="item" />
|
|
- <div v-if="isEnd">
|
|
|
|
- 没有更多了
|
|
|
|
|
|
+ <div
|
|
|
|
+ class="post-item"
|
|
|
|
+ style="padding: 8px; display: flex; justify-content: center"
|
|
|
|
+ v-if="isEnd"
|
|
|
|
+ >
|
|
|
|
+ <div>没有更多了😭</div>
|
|
</div>
|
|
</div>
|
|
- <div v-else @click="nextDatum">
|
|
|
|
|
|
+ <div
|
|
|
|
+ class="post-item show-more"
|
|
|
|
+ v-else
|
|
|
|
+ @click="nextDatum"
|
|
|
|
+ >
|
|
显示更多
|
|
显示更多
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</template>
|
|
</template>
|
|
|
|
|
|
<style scoped>
|
|
<style scoped>
|
|
|
|
+.show-more {
|
|
|
|
+ color: var(--secondary-text-color);
|
|
|
|
+ padding: 8px;
|
|
|
|
+ display: flex;
|
|
|
|
+ justify-content: center;
|
|
|
|
+ cursor: pointer;
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
+.show-more:hover {
|
|
|
|
+ color: var(--text-color);
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
|
|
</style>
|
|
</style>
|