1、引入html2canvas
npm install html2canvas --s
2、在组件中引入
import html2canvas from "html2canvas"
3、 给需要转成图片的内容节点加ref,便于获取
<div id="info" ref="html2canvas">
……
</div>
4、点击分享按钮,生成图片
shareBtn(){
html2canvas(this.$refs.html2canvas).then(canvas => {
// 生成图片地址
this.imgUrl = canvas.toDataURL("image/png");
});
}