详解Canvas 跨域脱坑实践

2020-04-25 08:12:25易采站长站整理

Failed to execute ‘toBlob’ on ‘HTMLCanvasElement’: Tainted canvases may not be exported.

如果你的图片服务允许跨域使用(如果不允许,见上条),那么你该考虑下给 img 元素加上 crossOrigin 属性,即:


const image = new Image()
image.crossOrigin = 'Anonymous'
image.src = src

如此,你便可以拿到图片数据了。如果没招,换同域资源吧~