Answer the question
In order to leave comments, you need to log in
Answer the question
In order to leave comments, you need to log in
<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);
},
},
});
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question