How to dynamically import images from public directory?
I have about 500 images, i don't want to write by hand patch to all of this files.
Images are located in sub directories for example cats, dogs, elephants. Every single directory contains 5-10 images.
Is there any way to import it dynamically?
4 Replies
Why not just put the images in the public directory and just call them by path?
https://nuxt.com/docs/getting-started/assets#public-directory
As i said in first line there is ton of images, would you write 500+ pathes by hand?
Maybe on your server-side you do
fs.readdir
or fs.readdirsync
to get the list of files, and then you can pass the results to your front-end to be displayed
https://nodejs.org/api/fs.html#fsreaddirpath-options-callbackNice, love that tip. Gonna try it out