1

I am using v-for to display collection of images using Vuetify v-img. We only store the image's Id which is then dynamically inserted into the src attribute of v-img. But dynamically inserting src value is not working. image.title is displayed but nothing is displayed for v-img. I have tried few other answers on SO but none worked. Does anybody know what is the correct way to do this?

<v-card max-width="400" v-for="image in images" :key="image.sourceId">
  {{image.title}}
  <v-img
      src="'https://img.imagestore.com/image/' + image.sourceId + '.jpg'">
  </v-img>
</v-card>

export default {
  data: () => ({
    images: [
      {
        id: "2",
        sourceId: "bMwG1R3sXnE",
        title: "Sunrise"
      },
      {
         id: "3",
         sourceId: "pqrwG1R3sXnE",
         title: "Amazon Forest"
      }
    ]
})        

1 Answer 1

1

Well, binding the src attribute made it work so instead of src use :src

  <v-img
    :src="'https://img.imagestore.com/image/' + image.sourceId + '.jpg'">
  </v-img>

or

  <v-img
    :src="`https://img.imagestore.com/image/${image.sourceId}.jpg`">
  </v-img>
Sign up to request clarification or add additional context in comments.

2 Comments

Great! Any kind of binding you have to give :
this is shorthand for v-bind:src

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.