问题:将上传的图片转成base64格式
解决方式:
getBase64(file) {
return new Promise((resolve, reject) => {
const reader = new FileReader();
let imgResult = '';
reader.readAsDataURL(file);
reader.onload = () => {
imgResult = reader.result;
};
reader.onerror = (error) => {
reject(error);
};
reader.onloadend = () => {
resolve(imgResult);
};
});
}