Struggling to display titles from api (RapidAPI)

I'm trying to learn Vue.js and I've started making a clone of MyAnimeList to practice. I'm attempting to display titles from api in h2. Can someone help me, please 🙏 ? Here's API screenshot (lightshot): https://prnt.sc/TWcfNnWIW2IR Here's the API link: https://rapidapi.com/felixeschmittfes/api/myanimelist Here's my code: https://stackblitz.com/edit/vitejs-vite-vfxqxd?file=src%2Fviews%2FTopAnime.vue
Lightshot
Screenshot
Captured with Lightshot
MyAnimeList
Search animes using MyAnimeList, or get anime information by using the id of the anime.
Vipe
StackBlitz
Vitejs - Vite (forked) - StackBlitz
Next generation frontend tooling. It's fast!
9 Replies
Tirius
Tirius6mo ago
You are using router-link but you have not install vue-router Fix this first
Vipe
VipeOP6mo ago
Done, thx
vince
vince6mo ago
I don't know how you set up your code exactly, but it might be a case of you not iterating through the array So for example you see that it returns to you an array of objects, so to display the first anime title, you'd have to call array[0].title You can do this in vanilla JS by doing something like this:
for (const anime in animes) {
console.log(anime.title);
}
for (const anime in animes) {
console.log(anime.title);
}
Now how to do that exactly in your Vue implementation, not sure... but hopefully this gives you a good starting point! Took a quick dive into Vue! Figured it out 🙂 let me know if this helps you: https://stackblitz.com/edit/vitejs-vite-mqewyz?file=src%2FApp.vue,src%2Fviews%2FTopAnime.vue,src%2Fcomponents%2FCardComponent.vue You were really close; you were calling animeInfo.animes.title in your CardComponent.vue -- if you remove .animes.title, you'll see animeInfo already is the Object, so you can call animeInfo.title directly This is because your animeInfo prop on CardComponent is an anime (which you've correctly iterated by using v-for="anime in animes" so it's an Object in the animes array (and not the array itself)
Vipe
VipeOP6mo ago
omg thank you so much, I love you Why does putting
:key
:key
and
v-for
v-for
in another HTML element fix my issue?
vince
vince6mo ago
Nope but that's the way to do it on the docs You have a list of titles so use the right tags
vince
vince6mo ago
Vue.js
Vue.js - The Progressive JavaScript Framework
Vipe
VipeOP6mo ago
ok, I didn't know. Thank you 👍 yes mb
vince
vince6mo ago
lol sorry if I came across as "stern" -- not my intention no need to apologize
Vipe
VipeOP6mo ago
You made my day, and thanks to you, I'll learn from my mistake. So, even if it was your intention, it wouldn't have been a problem.
Want results from more Discord servers?
Add your server