思路:用canvas绘制图片,调用canvas.toDataUrl('image/jpeg') 把图片转成base64
getBase64(url) {
var Img = new Image();
Img.crossOrigin = "Anonymous";
Img.src = url + "?time=" + new Date().valueOf();
Img.onload = function () {
var canvas = document.createElement("canvas"),
width = Img.width, //确保canvas的尺寸和图片一样
height = Img.height;
canvas.width = width;
canvas.height = height;
canvas.getContext("2d").drawImage(Img, 0, 0, width, height);
return canvas.toDataURL("image/jpeg")
};
};