Skip to content
This repository has been archived by the owner on Jun 5, 2024. It is now read-only.

Commit

Permalink
rewrite pre-config.ts with useAxios()
Browse files Browse the repository at this point in the history
  • Loading branch information
TaiSakuma committed Aug 17, 2023
1 parent 1e6bd15 commit 5204e1e
Showing 1 changed file with 7 additions and 16 deletions.
23 changes: 7 additions & 16 deletions src/stores/pre-config.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { ref, watchEffect } from "vue";
import { ref } from "vue";
import { defineStore } from "pinia";
import axios from "axios";
import { useAxios } from "@vueuse/integrations/useAxios";
import * as path from "path";

interface PreConfig {
Expand All @@ -9,21 +9,12 @@ interface PreConfig {

export const usePreConfigStore = defineStore("preConfig", () => {
const url = ref(path.join(import.meta.env.VITE_PUBLIC_PATH, "config.json"));
const loading = ref(true);
const error = ref<any>(null);
const preConfig = ref<PreConfig>();

watchEffect(async () => {
error.value = null;
try {
const response = await axios.get<PreConfig>(url.value);
preConfig.value = response.data;
} catch (e) {
error.value = e;
} finally {
loading.value = false;
}
});
const {
data: preConfig,
error,
isLoading: loading,
} = useAxios<PreConfig>(url.value);

return {
url,
Expand Down

0 comments on commit 5204e1e

Please sign in to comment.