I need to verify if the item object has a property called 'url' set. If it's not present, I would like to display a placeholder image. Here is an example of what I want to achieve:
<img
v-if="item.relationships.main_image.attributes.url"
:src="item.relationships.main_image.attributes.url"
:alt="item.attributes.name"
class="h-full w-full"
/>
<img v-else :src="require('@/assets/placeholder.png')" alt=""/>
The issue lies in the fact that my item object might not have any properties since the backend only sends those properties if there is actually an image associated with the item.
Is there a way to determine if an object possesses that deeply nested property?
Error encountered: Uncaught (in promise) TypeError: Cannot read properties of null (reading 'attributes')