Element-UI上传照片-转base64
 
<el-upload
	ref="elupload"
	class="avatar-uploader"
	action="#"
	:http-request="httpRequest"
	 :show-file-list="false"
	:before-upload="beforeAvatarUpload"
	>
	 <img v-if="imageUrl" :src="imageUrl" class="avatar">
	<i v-else class="el-icon-plus avatar-uploader-icon"></i>
</el-upload>
 
beforeAvatarUpload(file) {
	console.log(file)
 	this.imgName = file.name;
    this.nowFile = file;
},
httpRequest(data){
	this.imageUrl = URL.createObjectURL(data.file);
	
	const isPFX = data.file.type === 'image/jpeg' || data.file.type === 'image/jpg' || data.file.type === 'image/png';
	const isLt2M = data.file.size / 1024 / 1024 < 2;
	if (!isPFX) {
	 	this.$message.error("上传头像图片只能是 JPG、PNG、JPEG 格式!");
	}else if (!isLt2M) {
	 	this.$message.error("上传文件大小不能超过 2MB!");
	}else{
		this.getBase64(data.file).then(resBase64 => {
	 	this.fileBase64 = resBase64.split(',')[1]  
	 	this.tempUrl = resBase64.split(',')[1]
	 })
	}
},
 getBase64(file) {
       return new Promise((resolve, reject) => {
         let reader = new FileReader();
         let fileResult = "";
         reader.readAsDataURL(file);
      
         reader.onload = function() {
           fileResult = reader.result;
         };
      
         reader.onerror = function(error) {
           reject(error);
         };
      
         reader.onloadend = function() {
           resolve(fileResult);
         };
       });
     },