<div id="app">
<div v-if="!images.length">
<h2>Select an images</h2>
<input type="file" @change="onFileChange" multiple>
</div>
<div v-else>
<div v-for="(image, i) in images">
<img :src="image" />
<button @click="removeImage(i)">Remove image</button>
</div>
</div>
</div>
new Vue({
el: '#app',
data: {
images: [],
},
methods: {
onFileChange(e) {
this.createImages(e.target.files || e.dataTransfer.files);
},
createImages(files) {
[...files].forEach(file => {
const reader = new FileReader();
reader.onload = e => this.images.push(e.target.result);
reader.readAsDataURL(file);
});
},
removeImage(index) {
this.images.splice(index, 1);
},
},
});