前提:用的element-ui的上传组件,人家回我的是blob加密的http
(如:blob:http://localhost:8080/b878edea-e649-4f8d-b723-c3f25454141b)
现在开始转base64
const image = new Image() // 新建一个img标签(还没嵌入DOM节点)
//blob:http://localhost:8080/b878edea-e649-4f8d-b723-c3f25454141b
image.src = file.url;
image.onload = () => {
const canvas = document.createElement('canvas')
canvas.width = image.width
canvas.height = image.height
const context = canvas.getContext('2d')
context.drawImage(image, 0, 0, image.width, image.height);
let imgUrl = canvas.toDataURL() //图片的base64地址
console.log(imgUrl);
}
toDataURL:toDataURL