-1

i am new to sanity, i am struggling for displaying image from sanity

this is the code for my frontend enter image description here

is this the problem?

<img :src="pet.image.asset" :alt="`image of ${pet.name} `" />

and this is the result enter image description here

and lastly this is the sanity backend enter image description here

thank you!

i am expecting the image to be rendered!

DarkBee
  • 16,592
  • 6
  • 46
  • 58
kiroo
  • 9
  • 2
  • 1
    Please, do not post code as image, use code snippets insteads. You can refer to [how-to-ask](https://stackoverflow.com/help/how-to-ask). – Kapcash Aug 21 '23 at 12:15
  • Are you sure `pet.image.asset` is a valid url? Or is the problem that the sanity query doesn't return the image? – Kapcash Aug 21 '23 at 12:16
  • Please don't mark a question as resolved by editing the question's title, rather use the specific tools. If you found an answer to be useful then update that answer and mark it as accepted – DarkBee Aug 24 '23 at 12:14

1 Answers1

0

You can use Sanity Image component. It will automatically build img tag with href (Sanity CDN).

<li v-for="pet in data" :key="pet._id">
  <sanity-image :asset-id="pet.image.asset._ref" />
</li>
Zooly
  • 4,736
  • 4
  • 34
  • 54