下载 npm install --save html2canvas
需要的页面引入import html2canvasfrom "html2canvas"
需要生成的bom加ref
<div class="zhezhao_content" ref="imageWrapper">
<div class="huih">
</div>
事件(imgUrl就是生成图片的路径)
toImage() {
html2canvas(this.$refs.imageWrapper).then(canvas => {
let dataURL = canvas.toDataURL("image/png");
this.imgUrl = dataURL;
console.log(this.imgUrl)
if (this.imgUrl !=="") {
this.dialogTableVisible =true;
}
});
},