#Trouble with dynamic assets

7 messages · Page 1 of 1 (latest)

next mason
#

I'm trying to dynamically fetch assets but there seems to be an issue with Vite.
I've tried a lot of different variations, but none seem to work. Is there any Vite config I have to do?

Some of the variations I've tried:

<img :src="`~/assets/${step.img}`" />
<img :src="`~assets/${step.img}`" />
<img :src="`@/assets/${step.img}`" />
<img :src="`assets/${step.img}`" />
<img :src="`/assets/${step.img}`" />
frank stag
#

@next mason Put images inside /public folder
if you do so for example you put image in
/public/images/fund-1.png , /public/images/fund-2.png
you can access them like
<img :src="`/images/${step.img}`"
assuming that `${step.img}` will return fund-1.png or fund-2.png

next mason
#

I was hoping to understand how I could dynamically access images in the assets folder instead of using an alternate approach. Or does this mean that accessing images from the assets folder is not a nuxt3 thing?

frank stag
#

I think the only way to access them is to somehow import then. Since they are not publicly expose

#

you cannot load them as you want to load them at the moment

next mason
#

Ok, so the public folder is the way to go. But out of curiosity, how would I reconfigure Vite to allow this?

frank stag