0

Can I ask for help? How do you bind an image to a vue or simply put, how do you render an image from the array to vue? I will show you my code and How I have done it and explain it carefully to you.

Inside my template, I have this UL that displays 3 items inside my array. I wanted to retrieve my images from the array that I created on my javascript code.

<ul class="list-rendering"> <li v-for="item in items" v-bind:key="item"> <v-card style="padding: 10px;"> <div class="img-cont"> <v-img :src="require('@/assets/section/about.jpg')"></v-img> </div> <div class="text-cont"> <br> <base-subheading>{{ item.name }}</base-subheading> <h5>{{ item.price }}</h5> </div> </v-card> </li> </ul> export default { data () { return { items: [ { img: "@/assets/section/about.jpg", name: "Cuppy Cake", price: "$20.00" }, { img: "@/assets/section/social.jpg", name: "Red Velvet Cake", price: "$4.99" }, { img: "@/assets/section/testimonials.jpg", name: "Carrot Cake", price: "$3.00" } ] } } 

}

3
  • you don't seem to use item.img anywhere in your code Commented Nov 15, 2019 at 5:58
  • yes, because I manually required the url directly to the <v-img>. I want to know how ddo I fetch the image from array. Commented Nov 15, 2019 at 6:02
  • try <v-img :src="item.img"></v-img> Commented Nov 15, 2019 at 6:20

2 Answers 2

1

Try This...

<ul class="list-rendering"> <li v-for="item in items" v-bind:key="item"> <v-card style="padding: 10px;"> <div class="img-cont"> <img :src="item.img" alt="loading..."> </div> <div class="text-cont"> <br> <base-subheading>{{ item.name }}</base-subheading> <h5>{{ item.price }}</h5> </div> </v-card> </li> </ul> 
Sign up to request clarification or add additional context in comments.

Comments

0

Try this

<ul class="list-rendering"> <li v-for="item in items" v-bind:key="item"> <v-card style="padding: 10px;"> <div class="img-cont"> <v-img :src="require(item.img)"></v-img> </div> <div class="text-cont"> <br> <base-subheading>{{ item.name }}</base-subheading> <h5>{{ item.price }}</h5> </div> </v-card> </li> </ul> 

You need require(ITEM.IMG) to render the image if you are using an alias. If you are using relative path then you can straight away use :src="item.img"

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.