I am using VueJS 2.5.3 on a section (not SPA) of a blog backend that makes an API call to check for a featured image attached to the post.
If it finds one, it uses a child component to show the image. The problem is that the child component isn't rendering after the API call is successful and so neither is the image object passed to it.
As you can see in this GIF, the child component isn't rendering <!---->
, I have a v-if
on it to check if the image exists. However, if I click on the child component inside of Vue DevTools, the child component renders and shows the image as expected.
My question is why would a child component only render after clicking on it in Vue Devtools? Does Vue Devtools trigger some sort of an event when you click on a component?
Here is the child component:
<template>
<div v-if="showImage" class="featured-image-container" :class="[ size ]">
<img :src="processedSrc" alt="Featured Image">
</div>
</template>
<script>
export default {
props: {
image: {
type: Object
},
size: {
type: String,
required: true
}
},
data () {
return {
showImage: false
}
},
computed: {
processedSrc: function () {
if (this.image && typeof this.image === 'object') {
this.showImage = true
return this.image.sizes[this.size].file
} else {
this.showImage = false
}
}
}
}
</script>
And here is a link to the code for the parent and child components: