diff --git a/app/pages/index.vue b/app/pages/index.vue index b11e9dd..03b3947 100644 --- a/app/pages/index.vue +++ b/app/pages/index.vue @@ -1,6 +1,6 @@ @@ -133,47 +144,47 @@ const { getStrapiLocale } = useLocalizations(); const strapiLocale = getStrapiLocale(); - const carouselImages = ref([]); - const recommend_productions = ref([]); - const recommend_solutions = ref([]); - - const pending = ref(true); - - onMounted(async () => { - try { - const response = await findOne('homepage', undefined, { - populate: { - carousel: { - populate: '*', - }, - recommend_productions: { - populate: { - cover: { - populate: '*', - }, - }, - }, - recommend_solutions: { - populate: { - cover: { - populate: '*', - }, + const { data, pending, error } = useAsyncData('homepage', () => + findOne('homepage', undefined, { + populate: { + carousel: { + populate: '*', + }, + recommend_productions: { + populate: { + cover: { + populate: '*', }, }, }, - locale: strapiLocale, + recommend_solutions: { + populate: { + cover: { + populate: '*', + }, + }, + }, + }, + locale: strapiLocale, + }) + ); + + const carousel = computed(() => data.value?.data.carousel || []); + const recommend_productions = computed( + () => data.value?.data.recommend_productions || [] + ); + const recommend_solutions = computed( + () => data.value?.data.recommend_solutions || [] + ); + + watch(error, (value) => { + if (value) { + console.error('数据获取失败: ', value); + throw createError({ + statusCode: 500, + statusMessage: 'CMS数据获取失败', + fatal: true, }); - if (response.data) { - carouselImages.value = response.data.carousel || []; - recommend_productions.value = response.data.recommend_productions || []; - recommend_solutions.value = response.data.recommend_solutions || []; - console.log('推荐产品:', recommend_productions.value); - console.log('推荐解决方案:', recommend_solutions.value); - } - } catch (error) { - console.error('Error fetching homepage data:', error); - } finally { - pending.value = false; } }); @@ -213,6 +224,10 @@ line-height: 1.6; } + .carousel-section { + padding: 0; + } + .homepage-carousel .el-carousel__item { width: 100%; height: 33vw;