Answers for "display photo form input file vue"

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

Browse Popular Code Answers by Language