Finish to setup data access

This commit is contained in:
isUnknown 2024-07-11 12:42:29 +02:00
parent 90c998fa41
commit 80f72e7dc9
10 changed files with 73 additions and 36 deletions

View file

@ -1,7 +1,29 @@
import { defineStore } from "pinia";
export const useApiStore = defineStore("counter", () => {
function fetchData() {
async function fetchPageData() {
const isHomePage = window.location.pathname === "/";
const url = isHomePage
? `${window.location.href}home.json`
: `${window.location.href}.json`;
try {
const response = await fetch(url);
if (!response.ok) {
throw new Error(`HTTP error! status: ${response.status}`);
}
const data = await response.json();
return data;
} catch (error) {
console.error(
"Une erreur s'est produite lors de la récupération des données :",
error
);
throw error;
}
}
function fetchDataThroughKQL() {
const api = "/api/query";
const username = import.meta.env.VITE_USERNAME;
@ -42,5 +64,5 @@ export const useApiStore = defineStore("counter", () => {
});
}
return { fetchData };
return { fetchDataThroughKQL, fetchPageData };
});