<el-form-item label="头像" prop="pass"> <img v-bind:src="imgSrc" style="width: 100px;"> <input type="file" ref="myfile" id="fileId" v-on:change="changeImg()"> </el-form-item> data() { return { imgSrc: '', } // 选择图片 changeImg: function() { let myfile = this.$refs.myfile; let myimg = myfile.files[0]; // 原生JS读取文件的内置对象 let reader = new FileReader(); // 把文件路径提供给文件读取工具 reader.readAsDataURL(myimg); reader.onload = e => { let data = e.target.result; this.imgSrc = data; } },
标签:vue,读取,myfile,let,reader,data,myimg,图片 From: https://www.cnblogs.com/liweimingbk/p/17069299.html