Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR JAVASCRIPT

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);
  }
}
 
PREVIOUS NEXT
Tagged: #vue #input #file #image #preview
ADD COMMENT
Topic
Name
5+7 =