3π
β
events
needs to be a ref
or reactive
for it to be reactive in the template:
// EventList.vue π
import { onBeforeMount, ref } from 'vue'
export default {
name: 'EventList',
components: {
EventCard,
},
setup() { π
let events = ref([])
onBeforeMount(async () => {
const res = await axios.get('https://my-json-server.typicode.com/Tommydemian/real-world-vue-3/db')
const { data } = res
π
events.value = data.events
console.log(events.value)
})
return {
events,
}
},
}
π€tony19
1π
on your console events has another object called events you need to assign data to res.events
to access the main array of objects
you are passing events instead of event
<template>
<div class="home">
<EventCard v-for="event in events" :key="event.id" :event="event" />
</div>
</template> ```
π€muyah
1π
You just need to pass event
as props in EventCard and not events
. Since events
is the collection of data. It has to be looped again once taken into the child component as props. Since you are looping events in the parent component. It is better to pass only the event
through props.
<EventCard v-for="event in events" :key="event.id" :event="event" />
π€Sujith Sandeep
Source:stackexchange.com