useFetch help - not working/fetching data
hey I might be using this completely wrong because im still new to nuxtjs but here goes:
I am trying to use
useFetch
for getting data from https://valorant-api.com but it is not working. When I use old regular fetch
it works with no problems and I don't know why useFetch
is not working with the valorant-api. Because it works with now problem when I use it with the https://fakestoreapi.com/ api.
here is the code:
Valorant-API
An extensive API containing data of most in-game items, assets and more!
5 Replies
give it a read and see if it helps
https://nuxt.com/docs/api/composables/use-fetch
I tried reading it but it did not really help. But I did find out that the useFetch is actually working but I believe its returning the data as a string because when I outputed
agents
i got everything as a string. but when I try to access values within the data i cant because its undefined. soo yea
I got it working with the regular fetch for nowOkay great π.
I like using useFetch becoz it only runs on the server side and the same data is carried forward to the client side. The simple fetch would call the api 2 times server & client.
If the data returned is a string you can use JSON.parse(<string>) to make it an object
I see thanks! I will try this when I get home
well I found out that the data I get from the api is already a JS object (i think?) and when I specify the uuid of the map or the agent and then requst the
displayName
or splash
etc... then it works but there seems to be a problem for when I want it to fetch all the data from the api (all the maps or agents) and not only 1 map or agent.
When I useFetch all tha agents/maps instead of one it does not show me anything.
When I try to parse it I get 500 "[object Object]" is not valid JSON
now I am confused why its not working when I want to get the whole list of agents/mapsI am not sure what could be the extact reason for this π€. If you are saying $fetch works for you, use inside asyncData it would behave same as useFetch i.e. only render in the server side.
try parsing using this
JSON.parse(JSON.stringify(response))