first commit
This commit is contained in:
20
app/plugins/03.fetch_product_tree.ts
Normal file
20
app/plugins/03.fetch_product_tree.ts
Normal file
@@ -0,0 +1,20 @@
|
||||
import type {ProductTree} from "~~/types/banner";
|
||||
|
||||
export default defineNuxtPlugin(async () => {
|
||||
|
||||
|
||||
const { useProductTreeStore } = await import('@/stores/productTree')
|
||||
const productTreeStore = useProductTreeStore()
|
||||
|
||||
const config = useRuntimeConfig();
|
||||
const apiUrl = config.public.BASE_API_URL;
|
||||
|
||||
try {
|
||||
const data = await $fetch<ProductTree[]>(`${apiUrl}/api/v1/products-tree/`)
|
||||
if (data) {
|
||||
productTreeStore.setProductTree(data)
|
||||
}
|
||||
} catch (error) {
|
||||
console.error('Failed to fetch product tree:', error)
|
||||
}
|
||||
})
|
||||
Reference in New Issue
Block a user