npm安装:npm i dom-to-image
使用:
//引入
import domtoimage from 'dom-to-image';
//获取页面dom元素
var node = document.getElementById('my-node');
domtoimage.toPng(node)
.then(function (dataUrl) {
var img = new Image();
img.src = dataUrl;
document.body.appendChild(img);
})
.catch(function (error) {
console.error('oops, something went wrong!', error);
});