vue input file image preview
// template
<div id="app">
<input type="file" @change="onFileChange" />
<img v-if="url" :src="url" />
</div>
// script
data() {
return {
url: null,
}
},
methods: {
onFileChange(e) {
const file = e.target.files[0];
this.url = URL.createObjectURL(file);
}
}