20 lines
481 B
JavaScript
20 lines
481 B
JavaScript
|
//图片转base64
|
||
|
export function getBase64Image(src) {
|
||
|
return new Promise(resolve => {
|
||
|
let xhr = new XMLHttpRequest();
|
||
|
xhr.open('get', src, true);
|
||
|
xhr.responseType = 'blob';
|
||
|
xhr.onload = function() {
|
||
|
if (this.status == 200) {
|
||
|
let blob = this.response;
|
||
|
let oFileReader = new FileReader();
|
||
|
oFileReader.onload = function(e) {
|
||
|
const base64 = e.target.result;
|
||
|
resolve(base64);
|
||
|
};
|
||
|
oFileReader.readAsDataURL(blob);
|
||
|
}
|
||
|
};
|
||
|
xhr.send();
|
||
|
});
|
||
|
}
|