优化Pexels图片加载逻辑,当切换到背景图片标签页时才调用api获取图片

This commit is contained in:
jingrow 2026-01-22 01:27:24 +08:00
parent f844332a2d
commit fc8922eed8

View File

@ -1209,6 +1209,7 @@ const pexelsDisplayCount = ref(12)
const PEXELS_PER_PAGE = 80 // Fetch 80 images per API call
const PEXELS_DISPLAY_INCREMENT = 12 // Display 12 more images each time
const pexelsHasMore = ref(true) // Track if there are more images to fetch
const pexelsImagesLoaded = ref(false) // Track if Pexels images have been loaded
// Custom background images
const customBackgrounds = ref<string[]>([])
@ -1500,12 +1501,20 @@ const handleUrlSubmit = async () => {
}
}
// Watch for tab changes to lazy load Pexels images
watch(activeTab, (newTab) => {
// Lazy load Pexels images only when user switches to 'image' tab for the first time
if (newTab === 'image' && !pexelsImagesLoaded.value) {
pexelsImagesLoaded.value = true
fetchPexelsImages()
}
})
onMounted(() => {
window.addEventListener('resize', handleResize)
window.addEventListener('paste', handlePaste)
loadFavoriteColors()
loadCustomBackgrounds()
fetchPexelsImages()
})
onUnmounted(() => {