I am trying to generate src
link to each of my li
items generated by v-for
.
I have list of some Strings... ["Electronics","Furniture", "Cloths", "Sports", "Entertainment", "Others"]
and in each tag
src
.
For example:
First item is electronics so path would be @/assets/Electronics.png
and image would be displayed
Second item is Furniture so path would be @/assets/Furniture.png
What do I need to do to show that img
how do I need to define this path?
<ul class="menu-dropdown">
<li v-for="item in items" :key="item" class="center align-self-center">
<img class="float-left" :src="getPicture(item)" v-bind:alt="item" />
<a href="#"><h3>{{item}}</h3></a>
</li>
</ul>
<script>
export default {
name: 'Header',
props:{},
data() {
return {
items: ["Electronics", "Furniture", "Cloths", "Sports", "Entertainment", "Others"]
}
},
methods:{
getPicture(item){
return '@/assets/' + item + ".png"
}
}
}
</script>