getBase64Image(img) {
console.log(img, 'img1212121');
var canvas = document.createElement("canvas");
canvas.width = img.width;
canvas.height = img.height;
var ctx = canvas.getContext("2d");
ctx.drawImage(img, 0, 0, img.width, img.height);
var dataURL = canvas.toDataURL("image/png"); // 可选其他值 image/jpeg
return dataURL;
}
main(src, cb) {
const that = this;
console.log(878111111111111118);
var image = new Image();
image.src = src + '?v=' + Math.random(); // 处理缓存
image.crossOrigin = "*"; // 支持跨域图片(实际上还会出现跨域问题,本人自己公司服务器的图片还是不行,最后用的代理)
image.onload = function() {
var base64 = that.getBase64Image(image);
cb && cb(base64);
};
}
ccd() { //点击事件 可根据实际要求进行触发
console.log(8788);https://fc3tn.baidu.com/it/u=3025909226,1763324618&fm=202&src=bqdata
this.main('https://zl-pub.oss-cn-hangzhou.aliyuncs.com/data/ara-marketing/imgs/wxzlTalentbg.png', function(base64) {
console.log(base64);
});
}