0

I am trying to show images through v-for, but they do not appear.

<div v-for="(n, i) in images" :key="i">
    <v-img :src="{n}"></v-img>
</div>

...

images: [
     '../assets/thirdSection/Olivia.png',
     '../assets/thirdSection/Olivia.png',
     '../assets/thirdSection/luiz.png',
]
kissu
  • 40,416
  • 14
  • 65
  • 133
GobsRuiz
  • 512
  • 1
  • 4
  • 14
  • You really should not use `i` for the `:key`, it will be worse than using nothing. – kissu Apr 01 '21 at 12:05
  • @kissu Where are you reading that from? That’s totally untrue. As long as `i` is a string, it is actually recommended to use it as the key. – Terry Apr 01 '21 at 12:08
  • @Terry based on how it works essentially, but this is a good source to corroborate my tellings: https://stackoverflow.com/a/44531545/8816585 – kissu Apr 01 '21 at 12:12
  • 1
    please share your folder structure (where the componet is related to the images) – Arthur Borba Apr 01 '21 at 19:00
  • please show the full component code – Avraham Apr 01 '21 at 20:41

2 Answers2

3

You do not need to use {} juse remove those brackets from your :src binding

<div v-for="(n, i) in images" :key="i">
    <v-img :src="n"></v-img>
</div>

...

images: [
     '../assets/thirdSection/Olivia.png',
     '../assets/thirdSection/Olivia.png',
     '../assets/thirdSection/luiz.png',
]
Swapnil Soni
  • 965
  • 1
  • 10
  • 26
0

Try using require to load your local images:

<div v-for="(n, i) in images" :key="i">
    <v-img :src="require(n)"></v-img>
</div>

...

images: [
     '@/assets/thirdSection/Olivia.png',
     '@/assets/thirdSection/Olivia.png',
     '@/assets/thirdSection/luiz.png',
]

You just have to install file-loader to your modules and configure your webpack.

Doing it like that, your local image path is resolved into a url.

Arthur Borba
  • 403
  • 3
  • 16