图片跨域携带cookie
2019-10-11 本文已影响0人
爱代码的派派星
function getBase64Image(img) {
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");
return dataURL
}
const img = document.createElement('img');
img.crossOrigin = "use-credentials"; //注意存放顺序
img.src = this.host + '/captcha?merchantNum=' + this.merchantNum + '&tamp=' + this.timeTamp;
img.onload = ()=>{
this.imgSrc = getBase64Image(img);
this.imageLoad = false;
}
img.onerror = ()=>{
this.imageLoad = false;
this.getImg();
}
//img.crossOrigin = "Anonymous" img.crossOrigin = "use-credentials";