图片跨域携带cookie

 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"; 

你可能感兴趣的:(图片跨域携带cookie)