Last active
June 7, 2018 07:42
-
-
Save jswhisperer/0d9bec7963806495c6bfc979a3675f22 to your computer and use it in GitHub Desktop.
dynamic images from a folder
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<template> | |
<div v-for="(image, index) in images" :key="index"> | |
<img :src='image' alt="image"> | |
</div> | |
</template> | |
<script> | |
const { images } = process.env; | |
export default { | |
data() { | |
return { | |
images | |
} | |
} | |
} | |
</script> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const imagesFolder = "./static/images/"; | |
const fs = require("fs"); | |
const images = []; | |
fs.readdir(imagesFolder, (err, files) => { | |
files.forEach(file => { | |
images.push(`images/${file}`); | |
}); | |
}); | |
module.exports = { | |
env: { | |
images | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
@gregbenner I don't think you'd even need a try/catch: