Files
nuxtfiber/app/plugins/02.fetch_banner.ts
Beyhan Oğur 7b2b27a42c first commit
2026-04-26 22:18:17 +03:00

21 lines
525 B
TypeScript

import type { Banner } from "~~/types/banner";
export default defineNuxtPlugin(async () => {
const { useBannerStore } = await import('@/stores/banner')
const bannerStore = useBannerStore()
const config = useRuntimeConfig();
const apiUrl = config.public.BASE_API_URL;
try {
const data = await $fetch<Banner[]>(`${apiUrl}/api/v1/hero`)
if (data) {
bannerStore.setBanner(data)
}
} catch (error) {
console.error('Failed to fetch banners:', error)
}
})