Files
b2b/bo/src/stores/category.ts
2026-04-01 09:10:38 +02:00

41 lines
972 B
TypeScript

import { defineStore } from "pinia";
import { ref } from "vue";
const products = [
{name: "product name", price: 342432},
{name: "product name", price: 342432},
{name: "product name", price: 342432},
{name: "product name", price: 342432},
{name: "product name", price: 342432},
]
// type CategoryProducts = {}
export const useCategoryStore = defineStore('category', () => {
const idCategory = ref(0)
const categoryProducts = ref(products)
function setCategoryID(id: number) {
idCategory.value = id
}
async function getCategoryProducts() {
return new Promise<typeof products>((resolve) => {
setTimeout(() => {
// console.log('Fetching products from category id: ', idCategory.value);
resolve(categoryProducts.value)
}, 2000 * Math.random())
})
}
return {
idCategory,
getCategoryProducts,
setCategoryID
}
})