getBase64(imgUrl) {
let xhr = new XMLHttpRequest();
xhr.open('get', '/xxx.jpg', true);
xhr.responseType = 'blob';
xhr.onload = function() {
if (this.status == 200) {
//得到一个blob对象
let blob = this.response
let oFileReader = new FileReader();
oFileReader.onloadend = function(e) {
const base64 = e.target.result
};
oFileReader.readAsDataURL(blob)
};
xhr.send();
}
};
图片转base64
于 2024-03-21 17:10:39 首次发布