vue+element的上传图片如何转base64编码

getBase64(file) {
return new Promise(function(resolve, reject) {
    let reader = new FileReader();
    let imgResult = "";
    reader.readAsDataURL(file);
    reader.onload = function() {
        imgResult = reader.result;
    };
    reader.onerror = function(error) {
        reject(error);
    };
    reader.onloadend = function() {
        resolve(imgResult);
    };
});

},


this.getBase64(file.raw).then(res => {

                      this.ruleForm.imagebase=res
                     
   });

你可能感兴趣的:(vue+element的上传图片如何转base64编码)