2

I'm trying to display some images side by side in columns using this methodology:

<v-row> <v-col v-for="(n, i) in footerLogos" :key="i"> <v-img :src="`${n}`"></v-img> </v-col> </v-row> 

The array:

footerLogos: [ "@/assets/inc5000.jpg", "@/assets/inc-honor-roll.jpg", "@/assets/asa.jpg", "@/assets/soaringeagle.jpg", "@/assets/inahu.jpg", "@/assets/nahu-eagle.jpg", "@/assets/inc5000.jpg" ] 

To me this SHOULD work but it doesn't. What am I missing? Or is there a better/simpler way to do it? I've tried a few variations such as the paths being "@assets/...." versus "@/assets/..." but nothing seems to work. Surely I'm missing something simple. Please help! :)

I'm using Vue, Vuetify and Nuxt

1
  • no, this should not work. Something like :src="require('n')" should. There are enough resources for this approach in internet Commented Mar 10, 2020 at 18:59

3 Answers 3

3

If you need import some image from your file system, first you need import this file with a require function. Please, take a look in the code below...

footerLogos: [ require('~/assets/inc5000.jpg'), require('~/assets/inc-honor-roll.jpg'), require('~/assets//assets/asa.jpg'), require('~/assets/soaringeagle.jpg'), require('~/assets/inahu.jpg'), require('~/assets/nahu-eagle.jpg'), require('~/assets/inc5000.jpg') ] 

However, if you will use a imagem from some URL, some thing like (https://example.com/img01.png) you don't need use require, just use a correctly path and this will work propertly.

Sign up to request clarification or add additional context in comments.

Comments

1

Try this code:

<v-row> <v-col v-for="(n, i) in footerLogos" :key="i"> <v-img :src="require(`${n}`)"></v-img> </v-col> </v-row> footerLogos: [ "./assets/inc5000.jpg", "./assets/inc-honor-roll.jpg", "./assets/asa.jpg", "./assets/soaringeagle.jpg", "./assets/inahu.jpg", "./assets/nahu-eagle.jpg", "./assets/inc5000.jpg" ] 

Did'nt work for me with the @

1 Comment

@HenriqueVanKlaveren you are right, i fixed it, i added the require on the template.
0

You can’t use require if you are using Vite

Someone else found this which worked for me

For the Vite environment, the solution is to use new URL('[path_to_image]', import.meta.url).href

See my answer here

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.