The data on my vue js website is rendering, but I'm getting an undefined error in the console. I'm making an axios call in App.vue to go get data from my cms:
App.vue
async created() {
const strapiData = await getStrapiData();
// Update Vuex
this.$store.dispatch('setStrapi', strapiData);
}
then in one of my components, I'm calling the getter to retrieve the data that's stored in vuex:
About.vue
computed: {
aboutData() {
return this.$store.getters.strapiData.data.about
}
}
Which I then reference in my template code:
<img :src="aboutData.photo.name">
Everything renders fine, but this is the error I'm seeing in the web console:
TypeError: Cannot read property 'photo' of undefined
at a.r (About.vue?3e5e:1)
I think the issue has something to do with the order in which my components are being created. I'm importing all of my child components into App.vue rendering them there, but I think the child components are being created before the created lifecycle hook of app.vue :
App.vue script
components: {
'app-about' : About,
App.vue template
<template>
<div id="app">
<app-about></app-about>
</div>
</template>
Any one have an idea of what I'm missing? Thank you!
img :src="aboutData?aboutData.photo.name:''">
? – Boussadjra Brahim<img v-if="aboutData"/ :src="aboutData.photo.name">
- if this would work then your suspicions are right – Michał Sadowski