1.依赖安装
npm install html2canvas
2.需要截图的页面引入
import html2canvas from 'html2canvas';
3.代码示例
let self = this;
//这里使用类选择器定位截图元素 .ele-previewImportPage
html2canvas(document.querySelector(".ele-previewImportPage"))
.then((canvas) => {
// 将画布转换为图片 得到base64图片字符
var imageData = canvas.toDataURL();
// 调用接口上传到后端
self.$postAction(`/api/page/snapshot`, {
image: imageData,
});
});