1.npm安装
npm install --S html2canvas
2.设置ref
<div ref="img" style="padding:10px;background:#f5da55">
<h4 style="color:#000;">Hello world!</h4>
</div>
3.转换
<div v-show="is_img_show">
<img :src="imgSrc">
</div>
html2canvas(this.$refs.img).then(canvas => {//html 转 canvas
//canvas转img
this.imgSrc = canvas.toDataURL("image/png");
if (this.imgSrc !== "") {
this.is_img_show = true;
}
//canvas转img END
//document.body.appendChild(canvas); 给body添加canvas
});