New fetch for multiple data
This commit is contained in:
parent
d44c080a85
commit
b695d36e56
1 changed files with 22 additions and 0 deletions
22
src/utils/functions/fetchMultiApi.ts
Normal file
22
src/utils/functions/fetchMultiApi.ts
Normal file
|
|
@ -0,0 +1,22 @@
|
|||
import { ofetch } from 'ofetch'
|
||||
|
||||
const API = import.meta.env.VITE_BACKEND
|
||||
|
||||
export default async (api: string) => {
|
||||
try {
|
||||
const fetchResponse = await ofetch(API + api)
|
||||
|
||||
const resultObject: Record<string, any> = {}
|
||||
|
||||
for (let i = 1; i <= 10; i++) {
|
||||
const propertyName = `result${i}`
|
||||
if (fetchResponse.hasOwnProperty(propertyName)) {
|
||||
resultObject[propertyName] = fetchResponse[propertyName]
|
||||
}
|
||||
}
|
||||
|
||||
return resultObject
|
||||
} catch {
|
||||
return false
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue