refactor:create fetchOption
This commit is contained in:
parent
3a192c0d77
commit
122d9b06ca
1 changed files with 12 additions and 1 deletions
|
|
@ -1,9 +1,12 @@
|
||||||
import { ref } from 'vue';
|
import { ref } from 'vue';
|
||||||
import { defineStore } from 'pinia';
|
import { defineStore } from 'pinia';
|
||||||
|
import { useI18n } from 'vue-i18n';
|
||||||
|
|
||||||
const useOptionStore = defineStore('optionStore', () => {
|
const useOptionStore = defineStore('optionStore', () => {
|
||||||
const globalOption = ref();
|
const { locale } = useI18n();
|
||||||
|
|
||||||
|
const globalOption = ref();
|
||||||
|
const rawOption = ref();
|
||||||
function mapOption(value: string) {
|
function mapOption(value: string) {
|
||||||
for (const category in globalOption.value) {
|
for (const category in globalOption.value) {
|
||||||
if (globalOption.value.hasOwnProperty(category)) {
|
if (globalOption.value.hasOwnProperty(category)) {
|
||||||
|
|
@ -16,9 +19,17 @@ const useOptionStore = defineStore('optionStore', () => {
|
||||||
return value;
|
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 {
|
return {
|
||||||
globalOption,
|
globalOption,
|
||||||
|
|
||||||
|
fetchOption,
|
||||||
mapOption,
|
mapOption,
|
||||||
};
|
};
|
||||||
});
|
});
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue