diff --git a/src/stores/options/index.ts b/src/stores/options/index.ts index 44a3d4aa..bbe2a66b 100644 --- a/src/stores/options/index.ts +++ b/src/stores/options/index.ts @@ -1,9 +1,12 @@ import { ref } from 'vue'; import { defineStore } from 'pinia'; +import { useI18n } from 'vue-i18n'; const useOptionStore = defineStore('optionStore', () => { - const globalOption = ref(); + const { locale } = useI18n(); + const globalOption = ref(); + const rawOption = ref(); function mapOption(value: string) { for (const category in globalOption.value) { if (globalOption.value.hasOwnProperty(category)) { @@ -16,9 +19,17 @@ const useOptionStore = defineStore('optionStore', () => { return value; } + async function fetchOption() { + const resultOption = await fetch('/option/option.json'); + rawOption.value = await resultOption.json(); + if (locale.value === 'eng') globalOption.value = rawOption.value.eng; + if (locale.value === 'tha') globalOption.value = rawOption.value.tha; + } + return { globalOption, + fetchOption, mapOption, }; });