Files
b2b/bo/src/stores/category.ts
2026-03-24 12:26:23 +01:00

41 lines
973 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 id_category = ref(0)
const categoryProducts = ref(products)
function setCategoryID(id: number) {
id_category.value = id
}
async function getCategoryProducts() {
return new Promise<typeof products>((resolve) => {
setTimeout(() => {
console.log('Fetching products from category id: ', id_category.value);
resolve(categoryProducts.value)
}, 2000 * Math.random())
})
}
return {
id_category,
getCategoryProducts,
setCategoryID
}
})