first commit
This commit is contained in:
20
app/plugins/02.fetch_banner.ts
Normal file
20
app/plugins/02.fetch_banner.ts
Normal file
@@ -0,0 +1,20 @@
|
||||
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)
|
||||
}
|
||||
})
|
||||
Reference in New Issue
Block a user