weekCodeing / interview-answe

🌍 前端程序员训练 求星星 ✨ 各位同学可以在issues中提问,无论是实际项目中遇到的问题,或者是技术问题都可以, 大家一起解决💯 👍 😄。
http://www.dadaqianduan.cn/
76 stars 9 forks source link

[bug]239.Access to XMLHttpRequest at 'xxxx' from origin 'http://localhost:8080' has been blocked by CORS policy: No 'Access-Control-Allow-Origin' header is present on the requested resource. #239

Open webVueBlog opened 4 years ago

webVueBlog commented 4 years ago
var imgs = new Image();
imgs.crossOrigin = "Anonymous"; //注意存放顺序
imgs.src = "http://192.168.0.107/ZHCX/CGZSIMG/1.jpg";
imgs.onload = function () {
var canvas = document.createElement('canvas');
canvas.width = imgs.width;
canvas.height = imgs.height;
var ctx = canvas.getContext("2d");
ctx.drawImage(imgs, 0, 0, imgs.width, imgs.height);
var img1 = new Image();
img1.src = canvas.toDataURL("image/png");
alert("s")
}

imgs.onerror = function () {
alert("error")
}