html2canvas 将 dom 转海报图片下载
const options = {
backgroundColor: null,
canvas: canvas,
useCORS: true,
dpi: 300
};
console.log("获取指定的宽高", width, height, canvas);
html2canvas(canvasDom, options)
- 阿里云后台配置
Access-Control-Allow-Origin: *
,允许图片跨域访问
request header | img = new Image();
img.src="" | img = new Image();
img.crossOrigin = 'anonymous';
img.src="" |
---|
Sec-Fetch-Dest | image | image |
Sec-Fetch-Mode | no-cors | cors |
Sec-Fetch-Site | cross-site | cross-site |
- img.crossOrigin = ‘anonymous’;
- 对其理解:匿名模式,即请求的时候,不携带能够标识用户 cookie 信息
- 开启后,会发现请求 header 的 Sec-Fetch-Mode 会变成:cors,即要求后端设置 cors response header
- 如下图,是 html2cancavas

