@@ -13,8 +13,14 @@ interface Product {
1313 rating: number
1414}
1515
16+ interface Category {
17+ slug: string
18+ name: string
19+ url: string
20+ }
21+
1622const products = ref <Product []>([])
17- const categories = ref <string []>([])
23+ const categories = ref <Category []>([])
1824const selectedCategory = ref (' ' )
1925const searchQuery = ref (' ' )
2026const limit = 12
@@ -29,15 +35,15 @@ if (initialData.value) {
2935 skip .value = 12
3036}
3137
32- const { data : categoryData } = await useFetch <string []>(' https://dummyjson.com/products/categories' )
38+ const { data : categoryData } = await useFetch <Category []>(' https://dummyjson.com/products/categories' )
3339if (categoryData .value ) {
3440 categories .value = categoryData .value
3541}
3642
3743const fetchMore = async () => {
3844 if (loading .value || ! hasMore .value ) return
3945 loading .value = true
40-
46+
4147 let url = ` https://dummyjson.com/products?limit=${limit }&skip=${skip .value } `
4248 if (selectedCategory .value ) {
4349 url = ` https://dummyjson.com/products/category/${selectedCategory .value }?limit=${limit }&skip=${skip .value } `
@@ -62,7 +68,7 @@ const handleFilter = async () => {
6268}
6369
6470// Intersection Observer for infinite scroll
65- const observerTarget = ref (null )
71+ const observerTarget = ref < HTMLElement | null > (null )
6672onMounted (() => {
6773 const observer = new IntersectionObserver ((entries ) => {
6874 if (entries [0 ].isIntersecting ) {
@@ -104,9 +110,12 @@ useSeoMeta({
104110 class =" input-field bg-surface-container-lowest border-none rounded-lg px-4 py-2 text-white/70 focus:ring-2 focus:ring-secondary/50 h-full min-h-[42px] appearance-none cursor-pointer"
105111 >
106112 <option value =" " >Все категории</option >
107- <option v-for =" cat in categories" :key =" cat" :value =" cat" >
108- {{ cat }}
109- <!-- {{ cat.charAt(0).toUpperCase() + cat.slice(1) }} -->
113+ <option
114+ v-for =" cat in categories"
115+ :key =" cat.slug"
116+ :value =" cat.slug"
117+ >
118+ {{ cat.name }}
110119 </option >
111120 </select >
112121 </div >
@@ -130,7 +139,7 @@ useSeoMeta({
130139 ${{ product.price }}
131140 </div >
132141 </div >
133-
142+
134143 <div class =" flex-grow flex flex-col gap-2" >
135144 <div class =" text-xs text-white/40 uppercase tracking-widest" >{{ product.category }}</div >
136145 <h3 class =" text-lg font-heading font-bold line-clamp-1 group-hover:text-primary transition-colors" >
0 commit comments