Create product cards, display all on products page

This commit is contained in:
2024-09-06 17:10:21 +02:00
parent 22cc811ae5
commit babf1c77ce
11 changed files with 253 additions and 19 deletions

View File

@@ -0,0 +1,41 @@
<script setup lang="ts">
import productCard from "./productCard.vue"
import filterBar from "./filterBar.vue"
import axios from "axios";
import { Ref, ref } from "vue";
import { ProductModel } from "@/data/models/productModel";
import { CategoryModel } from "@/data/models/categoryModel";
const products: Ref<Array<ProductModel>> = ref<Array<ProductModel>>([])
const categories: Ref<Array<CategoryModel>> = ref<Array<CategoryModel>>([])
axios.get("http://127.0.0.1:3000/categories")
.then(function (response) {
categories.value = response.data
})
axios.get("http://127.0.0.1:3000/products")
.then(function (response) {
products.value = response.data
})
function getCategoryById(id: number) {
return categories.value.find(category =>
category.id === id
)
}
</script>
<template>
<v-row>
<v-col>
<filter-bar :number-of-items="products.length" />
</v-col>
</v-row>
<v-row dense>
<v-col v-for="product in products" cols="6" lg="4" xl="3">
<product-card :product="product" :category="getCategoryById(product.categoryId)" />
</v-col>
</v-row>
</template>