fix fetch
This commit is contained in:
@ -1,8 +1,11 @@
|
||||
import { usePB } from "~/composables/usePB";
|
||||
import type {
|
||||
CountryList,
|
||||
Country,
|
||||
Currencies,
|
||||
Currency,
|
||||
FooterListResponse,
|
||||
GenericResponse,
|
||||
GenericResponseItems,
|
||||
MenuListResponse,
|
||||
PBFooterItem,
|
||||
PBMenuItem,
|
||||
@ -10,6 +13,7 @@ import type {
|
||||
} from "~/types";
|
||||
import { useStore } from "./store";
|
||||
import { ref, watch } from "vue";
|
||||
import { useMyFetch } from "#imports";
|
||||
|
||||
function buildTreeRecursive(
|
||||
data: (PBMenuItem | UIMenuItem)[],
|
||||
@ -41,8 +45,8 @@ export const useMenuStore = defineStore("menuStore", () => {
|
||||
const menuItems = ref<MenuListResponse>();
|
||||
|
||||
const footerItems = ref<FooterListResponse>();
|
||||
const countryList = ref<CountryList[]>();
|
||||
const currencies = ref<Currencies[]>();
|
||||
const countryList = ref<Country[]>();
|
||||
const currencies = ref<Currency[]>();
|
||||
|
||||
// curr/country
|
||||
const selectedCountry = ref();
|
||||
@ -87,8 +91,8 @@ export const useMenuStore = defineStore("menuStore", () => {
|
||||
|
||||
const getCountryList = async () => {
|
||||
try {
|
||||
const res = await fetch(
|
||||
`http://127.0.0.1:4000/api/public/country/list`,
|
||||
const {data} = await useMyFetch<GenericResponse<Country[]>>(
|
||||
`/api/public/country/list`,
|
||||
{
|
||||
headers: {
|
||||
"Content-Type": "application/json",
|
||||
@ -96,12 +100,12 @@ export const useMenuStore = defineStore("menuStore", () => {
|
||||
}
|
||||
);
|
||||
|
||||
if (!res.ok) {
|
||||
throw new Error(`HTTP error: ${res.status}`);
|
||||
}
|
||||
// if (!res.ok) {
|
||||
// throw new Error(`HTTP error: ${res.status}`);
|
||||
// }
|
||||
|
||||
const data = await res.json();
|
||||
countryList.value = data.data
|
||||
// const data = await res.json();
|
||||
countryList.value = data
|
||||
if (countryList.value)
|
||||
selectedPhoneCountry.value = countryList.value[0]
|
||||
|
||||
@ -112,21 +116,25 @@ export const useMenuStore = defineStore("menuStore", () => {
|
||||
|
||||
const getCurrencies = async () => {
|
||||
try {
|
||||
const res = await fetch(
|
||||
`http://127.0.0.1:4000/api/public/currencies`,
|
||||
const {data} = await useMyFetch<GenericResponseItems<Currency[]>>(
|
||||
`/api/public/currencies`,
|
||||
{
|
||||
headers: {
|
||||
"Content-Type": "application/json",
|
||||
},
|
||||
onErrorOccured: (_, status) => { throw new Error(`HTTP error: ${status}`) },
|
||||
}
|
||||
);
|
||||
|
||||
if (!res.ok) {
|
||||
throw new Error(`HTTP error: ${res.status}`);
|
||||
}
|
||||
// if (!res.ok) {
|
||||
// throw new Error(`HTTP error: ${res.status}`);
|
||||
// }
|
||||
|
||||
const data = await res.json();
|
||||
currencies.value = data.data.items
|
||||
// const data = await res.json();
|
||||
currencies.value = data.items
|
||||
|
||||
// console.log(data.items, "data");
|
||||
|
||||
} catch (error) {
|
||||
console.error("getList error:", error);
|
||||
}
|
||||
|
Reference in New Issue
Block a user