claude 5
This commit is contained in:
27
frontend/src/stores/achats.js
Normal file
27
frontend/src/stores/achats.js
Normal file
@@ -0,0 +1,27 @@
|
||||
// frontend/src/stores/achats.ts
|
||||
import { defineStore } from 'pinia';
|
||||
import { ref } from 'vue';
|
||||
import { achatsApi } from '@/api/achats';
|
||||
export const useAchatsStore = defineStore('achats', () => {
|
||||
const achats = ref([]);
|
||||
const loading = ref(false);
|
||||
async function fetchAll(params) {
|
||||
loading.value = true;
|
||||
try {
|
||||
achats.value = await achatsApi.list(params);
|
||||
}
|
||||
finally {
|
||||
loading.value = false;
|
||||
}
|
||||
}
|
||||
async function create(a) {
|
||||
const created = await achatsApi.create(a);
|
||||
achats.value.unshift(created);
|
||||
return created;
|
||||
}
|
||||
async function remove(id) {
|
||||
await achatsApi.delete(id);
|
||||
achats.value = achats.value.filter(a => a.id !== id);
|
||||
}
|
||||
return { achats, loading, fetchAll, create, remove };
|
||||
});
|
||||
Reference in New Issue
Block a user