//imgurl 图片url
export function getBase64ByURL (imgUrl) {
return new Promise(resolve => {
window.URL = window.URL || window.webkitURL;
var xhr = new XMLHttpRequest();
xhr.open("get", imgUrl, true);
xhr.responseType = "blob";
xhr.onload = function () {
if (this.status == 200) {
var blob = this.response;
let oFileReader = new FileReader();
oFileReader.onloadend = function (e) {
resolve({blob,base64:e.target.result})
};
oFileReader.readAsDataURL(blob);
}
};
xhr.send();
})
},
//============
// 调用
getBase64ByURL(url).then(res=>{
let {blob,base64} = res
console.log(blob,base64,"blob,base64")
})