Skip to content

Instantly share code, notes, and snippets.

@PKTseng
Created August 11, 2020 13:19
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save PKTseng/6021dcb601d9caf875d87589567c8979 to your computer and use it in GitHub Desktop.
Save PKTseng/6021dcb601d9caf875d87589567c8979 to your computer and use it in GitHub Desktop.
圖片上傳
<div id="app">
<input type="file" @change="selectFile">
<img :src="image" width="200">
</div>
new Vue({
el:"#app",
data:{
image: '',
},
methods:{
selectFile(e){
const file = e.target.files.item(0);
// console.log(file);
const reader = new FileReader();
reader.addEventListener('load', this.imageLoaded);
reader.readAsDataURL(file);
},
imageLoaded(e){
this.image = e.target.result;
},
},
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment