Answers for "vue input file image preview"

1

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);
  }
}
Posted by: Guest on August-11-2021

Code answers related to "vue input file image preview"

Browse Popular Code Answers by Language