bsae64压缩地址(借鉴):
https://blog.csdn.net/weixin_42752574/article/details/126061352
文件转换base64:
function getBase64(file: any) {
return new Promise(function (resolve, reject) {
const 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);
};
});
}
base64调用:
getBase64(uploadFile.raw).then((res: any) => {
compressImg(res, 0.5, useImg, res);
});