您所在的位置:首页 / 知识分享

html2canvas

2023.04.07

311

左迁

html2canvas使用

npm install --save html2canvas

import html2canvas from 'html2canvas';

<div ref="picture"> <h4>Hello world!</h4> </div>

// 配置项 const setup = { useCORS: true, // 使用跨域 }; html2canvas(this.$refs.picture, setup).then((canvas) => { document.body.appendChild(canvas); // 自动在下方显示绘制的canvas图片 });

作者:前端学习笔记_zxh
链接:https://juejin.cn/post/7207342547361267771
来源:稀土掘金
著作权归作者所有。商业转载请联系作者获得授权,非商业转载请注明出处。


// 生成图片 creatImg() { const setup = { useCORS: true, // 使用跨域 }; html2canvas(this.$refs.picture, setup).then((canvas) => { const link = canvas.toDataURL("image/jpg"); this.exportPicture(link, "文件名"); }); } // 导出图片 exportPicture(link, name = "未命名文件") { const file = document.createElement("a"); file.style.display = "none"; file.href = link; file.download = decodeURI(name); document.body.appendChild(file); file.click(); document.body.removeChild(file); }

作者:前端学习笔记_zxh
链接:https://juejin.cn/post/7207342547361267771
来源:稀土掘金
著作权归作者所有。商业转载请联系作者获得授权,非商业转载请注明出处。

相关新闻

CSS 预编译语言 LESS 基础

2018.10.12

2369

我们大家都知道HTML和CSS不属于编程语言而是属于标记语言,所以很难像JS一样定义变量、编写方法、实现模块化开发等。

SEM少花钱的技巧

2015.11.12

3248