Skip to content

Instantly share code, notes, and snippets.

@jswhisperer
Last active June 7, 2018 07:42
Show Gist options
  • Save jswhisperer/0d9bec7963806495c6bfc979a3675f22 to your computer and use it in GitHub Desktop.
Save jswhisperer/0d9bec7963806495c6bfc979a3675f22 to your computer and use it in GitHub Desktop.
dynamic images from a folder
<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>
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
}
}
@developius
Copy link

@gregbenner I don't think you'd even need a try/catch:

> const [title, description] = "Title Of the Image".split(".", 2)
> title
"title Of the image"
> description
undefined

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment