I’m currently learning Vue.js and working on a MyAnimeList clone for practice. However, I am struggling to display anime titles correctly. I would appreciate any guidance on resolving this issue.
Here’s some relevant code:
<template>
<div class="topAnime">
<h1>Featured Anime</h1>
<div class="card">
<AnimeCard v-for="show in shows" :key="show.id" :showData="show"/>
</div>
</div>
</template>
<script setup>
import AnimeCard from "../components/AnimeCard.vue";
import { onMounted, ref } from "vue";
const shows = ref([]);
onMounted(() => {
const apiUrl = 'https://anime-db.p.rapidapi.com/anime?page=1&size=10';
const requestOptions = {
method: 'GET',
headers: {
'x-rapidapi-key': '5ba5251626msh61775206ad42e40p1981dbjsn73e0574f7887',
'x-rapidapi-host': 'anime-db.p.rapidapi.com'
}
};
fetch(apiUrl, requestOptions)
.then(response => response.json())
.then(data => {
shows.value = data.contents;
})
.catch(error => console.error('Error fetching data', error));
});
</script>
<style scoped>
a {
color: black;
text-decoration: none;
}
</style>
Here’s the card component code:
<template>
<div>
<h2>{{ showData.animes.title }}</h2>
</div>
</template>
<script setup>
defineProps({
showData: Object
});
</script>
<style scoped>
</style>
I have tested various methods with <h2>
and Fetch but have not had any luck.