Answer the question
In order to leave comments, you need to log in
How to pass data from v-for to child component?
Essence: there is a component that loads the list of categories
<template>
<div class="row">
<div class="col-md-3" v-for="item in genres">
<Genre :key="item.id" :name="item.name"></Genre>
</div>
</div>
</template>
<script>
export default {
data() {
return {
genres: {}
}
},
components: {
Genre: () => import('./Genre')
},
methods: {
getGenres() {
this.axios.get(`https://api.themoviedb.org/3/genre/movie/list?api_key=${this.api_key}`)
.then( response => this.genres = response.data.genres )
.catch( err => console.log(err))
}
},
mounted() {
this.getGenres()
}
}
</script>
<template>
<div class="card">
<div class="card-body">
<h5 class="card-title">{{ name }}</h5>
<a href="#" class="btn btn-primary">К фильмам</a>
</div>
</div>
</template>
<script>
export default {
props: [name]
}
</script>
vue.runtime.esm.js?2b0e:619 [Vue warn]: Property or method "name" is not defined on the instance but referenced during render. Make sure that this property is reactive, either in the data option, or for class-based components, by initializing the property. See: https://vuejs.org/v2/guide/reactivity.html#Declaring-Reactive-Properties.
found in
---> <Genre> at src/components/Genre.vue
<Genres> at src/components/Genres.vue
<Home> at src/views/Home.vue
<App> at src/App.vue
<Root>
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question