Skip to content

Commit

Permalink
feat: 增加骨架屏效果
Browse files Browse the repository at this point in the history
  • Loading branch information
Plumbiu committed Jan 27, 2023
1 parent 494d396 commit 3903563
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 9 deletions.
Binary file modified backend/.tmp/data.db
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
"name": "Apache 2.0",
"url": "https://www.apache.org/licenses/LICENSE-2.0.html"
},
"x-generation-date": "2023-01-27T04:58:57.064Z"
"x-generation-date": "2023-01-27T08:40:22.000Z"
},
"x-strapi-config": {
"path": "/documentation",
Expand Down
12 changes: 7 additions & 5 deletions frontend/components/Articles/index.vue
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
<script setup lang="ts">
const route = useRoute()
let pagenum = 0
const type = route.path.replace('/', '')
const sort = route.query?.sort as string | undefined
let pagenum = 1
const isLoading = useState('isLoading', () => false)
const artlistData = useArtlist(await useFetchPostData())
const addArtListItem = () => {
if (useScrollBottom()) {
const timer = setTimeout(async () => {
if (useScrollBottom()) {
pagenum++
const type = route.path.replace('/', '')
const sort = route.query?.sort as (string | undefined)
const newArtlistData = await useFetchPostData(type, sort, pagenum)
artlistData.value.push(...newArtlistData)
}
Expand All @@ -18,10 +18,12 @@ const addArtListItem = () => {
}
}
watchEffect(() => {
// eslint-disable-next-line no-console
console.log(type, sort)
const type = route.path.replace('/', '')
const sort = route.query?.sort as (string | undefined)
isLoading.value = true
useFetchPostData(type, sort).then((data) => {
artlistData.value = data
isLoading.value = false
})
})
onMounted(() => {
Expand Down
5 changes: 2 additions & 3 deletions frontend/composables/useFetchPostData.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,8 @@ export const useArtlistPath = (path?: string | undefined) => useState('artlistPa
// TODO: 请求数据
export default async (type?: string, sort = 'recommended', pagenum = 1): Promise<IPanel[]> => {
// 接口
const { data: fetchData } = await useFetch(`/api/articles/list?sort=${sort}&type=${type}&pageNum=${pagenum}`)
const data = fetchData.value.articles.data
const value: IPanel[] = data.map((item: IArticleItem) => {
const { data } = await useFetch(`/api/articles/list?sort=${sort}&type=${type}&pageNum=${pagenum}`)
const value: IPanel[] = data.value.map((item: IArticleItem) => {
const tagIds: string[] = []
item.tagIds.data.forEach((sub) => {
tagIds.push(sub.tag)
Expand Down

0 comments on commit 3903563

Please sign in to comment.