File tree Expand file tree Collapse file tree 2 files changed +34
-16
lines changed Expand file tree Collapse file tree 2 files changed +34
-16
lines changed Original file line number Diff line number Diff line change 4
4
<ProductSort />
5
5
</div >
6
6
<div id =" product-container" class =" flex flex-wrap items-center" >
7
- <template v-if =" store .loading " >
8
- <SpinnerLoading />
9
- </template >
10
- <template v-else-if =" store .error " >
11
- <p >Error loading products.</p >
12
- </template >
13
- <template v-else >
7
+ <template v-if =" products .length > 0 " >
14
8
<ProductCard
15
- v-for =" product in store.filteredProducts "
9
+ v-for =" product in products "
16
10
:key =" product.id"
17
11
:product =" product"
18
12
/>
19
13
</template >
14
+ <template v-else >
15
+ <p >No products are available.</p >
16
+ </template >
20
17
</div >
21
18
</div >
22
19
</template >
23
20
24
21
<script setup>
25
- import { useProductsStore } from " @/store/useProductsStore" ;
26
-
27
- const store = useProductsStore ();
28
-
29
- if (store .products .length === 0 ) {
30
- await store .fetchProducts ();
31
- }
22
+ defineProps ({
23
+ products: {
24
+ type: Array ,
25
+ required: true ,
26
+ },
27
+ });
32
28
</script >
Original file line number Diff line number Diff line change 2
2
<div class =" container mx-auto" >
3
3
<div class =" flex flex-wrap" >
4
4
<ProductFilter />
5
- <ProductGrid />
5
+ <div class =" w-full md:w-3/4 p-4" >
6
+ <template v-if =" pending " >
7
+ <SpinnerLoading />
8
+ </template >
9
+ <template v-else-if =" error " >
10
+ <p >Error loading products.</p >
11
+ </template >
12
+ <template v-else >
13
+ <ProductGrid :products =" store.filteredProducts" />
14
+ </template >
15
+ </div >
6
16
</div >
7
17
</div >
8
18
</template >
9
19
10
20
<script setup>
21
+ import { useProductsStore } from " @/store/useProductsStore" ;
22
+ import FETCH_ALL_PRODUCTS_QUERY from " @/apollo/queries/FETCH_ALL_PRODUCTS_QUERY.gql" ;
23
+
24
+ const store = useProductsStore ();
25
+
26
+ const { data , pending , error } = await useAsyncQuery (FETCH_ALL_PRODUCTS_QUERY );
27
+
28
+ if (data .value ) {
29
+ store .products = data .value .products .nodes ;
30
+ store .productTypes = store .getUniqueProductTypes ;
31
+ }
32
+
11
33
useHead ({
12
34
title: " Products" ,
13
35
titleTemplate: " %s - Nuxt 3 Woocommerce" ,
You can’t perform that action at this time.
0 commit comments