Reapply "feat: reuse server data on home page"

This reverts commit 6d277b5809.
This commit is contained in:
tim
2025-08-11 00:41:34 +08:00
parent 582873e505
commit dbeaefe9ba

View File

@@ -109,6 +109,7 @@
<script>
import { ref, watch } from 'vue'
import { useRoute } from 'vue-router'
import { useState } from '#app'
import { useScrollLoadMore } from '~/utils/loadMore'
import { stripMarkdown } from '~/utils/markdown'
import { API_BASE_URL } from '~/main'
@@ -152,8 +153,8 @@ export default {
.map(v => (isNaN(v) ? v : Number(v)))
}
const tagOptions = ref([])
const categoryOptions = ref([])
const tagOptions = useState('index-tagOptions', () => [])
const categoryOptions = useState('index-categoryOptions', () => [])
const isLoadingPosts = ref(false)
const topics = ref(['最新回复', '最新', '排行榜' /*, '热门', '类别'*/])
const selectedTopic = ref(
@@ -164,11 +165,12 @@ export default {
: '最新回复'
)
const articles = ref([])
const page = ref(0)
const articles = useState('index-articles', () => [])
const page = useState('index-page', () => 0)
const pageSize = 10
const allLoaded = useState('index-allLoaded', () => false)
const initialized = useState('index-initialized', () => false)
const isMobile = useIsMobile()
const allLoaded = ref(false)
const loadOptions = async () => {
if (selectedCategory.value && !isNaN(selectedCategory.value)) {
@@ -381,7 +383,10 @@ export default {
const sanitizeDescription = text => stripMarkdown(text)
await Promise.all([loadOptions(), fetchContent()])
if (!initialized.value) {
await Promise.all([loadOptions(), fetchContent()])
initialized.value = true
}
return {
topics,